From 512834106c407378965c5384c87075847b850791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Fri, 18 Oct 2024 23:50:11 +0800 Subject: [PATCH] pengyuthon --- preview_easy/__manifest__.py | 33 +++++++++++------------ preview_easy/controllers/preview.py | 41 ++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/preview_easy/__manifest__.py b/preview_easy/__manifest__.py index 9ec4f3da5..5929f3b8f 100644 --- a/preview_easy/__manifest__.py +++ b/preview_easy/__manifest__.py @@ -11,34 +11,33 @@ 'author': 'zxltwins', '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', diff --git a/preview_easy/controllers/preview.py b/preview_easy/controllers/preview.py index 08b396361..f6c05b9a6 100644 --- a/preview_easy/controllers/preview.py +++ b/preview_easy/controllers/preview.py @@ -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/', type='http',method=['Get'], auth="user") + @http.route('/web/content/preview/', 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""" + + + + + + + + + + """, 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')])