pengyuthon
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
'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',
|
||||
@@ -26,7 +26,6 @@
|
||||
],
|
||||
'web.assets_frontend': [
|
||||
|
||||
|
||||
],
|
||||
'web.assets_tests': [
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import werkzeug,io
|
||||
import werkzeug, io
|
||||
import werkzeug.exceptions
|
||||
import werkzeug.utils
|
||||
import werkzeug.wrappers
|
||||
@@ -7,19 +7,23 @@ from odoo import http
|
||||
from odoo.http import request
|
||||
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')])
|
||||
|
||||
Reference in New Issue
Block a user