pengyuthon

This commit is contained in:
李鹏宇
2024-10-18 23:50:11 +08:00
parent dab0bece34
commit 512834106c
2 changed files with 47 additions and 27 deletions
+16 -17
View File
@@ -11,34 +11,33 @@
'author': 'zxltwins<email:444713077@qq.com>',
'website': "www.odoo.com",
'version': '17.0',
"depends": ["base",'sale'],
"depends": ["base", 'sale'],
"external_dependencies": {"python": ["mammoth"]},
"data": [
'security/ir.model.access.csv',
'views/preview.xml'],
'assets': {
'web._assets_primary_variables': [
'web._assets_primary_variables': [
],
'web.assets_backend': [
'preview_easy/static/src/js/qweb.js',
'preview_easy/static/src/xml/qweb.xml'
],
'web.assets_frontend': [
],
'web.assets_backend': [
'preview_easy/static/src/js/qweb.js',
'preview_easy/static/src/xml/qweb.xml'
],
'web.assets_frontend': [
],
'web.assets_tests': [
],
'web.assets_tests': [
],
],
'web.report_assets_common': [
'web.report_assets_common': [
],
'web.report_assets_pdf': [
],
'web.report_assets_pdf': [
],
},
],
},
'images': [
'static/description/main_screenshot.png',
+31 -10
View File
@@ -1,25 +1,29 @@
import werkzeug,io
import werkzeug, io
import werkzeug.exceptions
import werkzeug.utils
import werkzeug.wrappers
import werkzeug.wsgi
from odoo import http
from odoo.http import request
from jinja2 import Environment, PackageLoader
from jinja2 import Environment, PackageLoader
import mammoth
class preview(http.Controller):
@http.route('/web/content/preview/<int:id>', type='http',method=['Get'], auth="user")
@http.route('/web/content/preview/<int:id>', type='http', method=['Get'], auth="user")
def content_preview(self, id=None):
ir_attach = request.env['ir.attachment'].sudo()
attach = ir_attach.browse(id)
image=['image/jpeg','image/png', 'image/bmp','image/gif', 'image/jpg','image/svg']
html=['text/html']
video=['video/mp4','video/webm','video/wmv','video/asf','video/divx','video/rm','video/mkv','video/flv','video/3gp',
'video/wma','video/wav','video/ape','video/mpeg','video/mpg']
pdf=[ 'application/pdf']
txt=['text/plain']
word=['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
image = ['image/jpeg', 'image/png', 'image/bmp', 'image/gif', 'image/jpg', 'image/svg']
html = ['text/html']
video = ['video/mp4', 'video/webm', 'video/wmv', 'video/asf', 'video/divx', 'video/rm', 'video/mkv',
'video/flv', 'video/3gp',
'video/wma', 'video/wav', 'video/ape', 'video/mpeg', 'video/mpg']
pdf = ['application/pdf']
txt = ['text/plain']
excel = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']
word = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']
env = Environment(loader=PackageLoader('odoo.addons.preview_easy', 'static/src/xml'))
template = env.get_template('1.html')
if attach:
@@ -31,6 +35,23 @@ class preview(http.Controller):
result = mammoth.convert_to_html(file)
html = result.value
return template.render(html=html)
elif attach.mimetype in excel:
# base_url = env['ir.config_parameter'].sudo().get_param('web.base.url')
# env.cr.dbname
# html = "https://view.officeapps.live.com/op/view.aspx?src=" + "https://pengyuthon.com" + "/web/content/" + id
html = "https://view.officeapps.live.com/op/view.aspx?src=" + "http://youthpower.ltd/blogger_lib_admin/test.xlsx"
return werkzeug.wrappers.Response(f"""
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body onLoad="parent.location='{html}'">
</body>
</html>
""", status=200, headers=[('Content-Type', 'text/html'), ('charset', 'utf-8')])
else:
return werkzeug.wrappers.Response('This format is not currently supported', status=200, headers=[('Content-Type', 'text/html'),('charset','utf-8')])