forked from rainbow-studio-solution/wecom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
完成 邀请用户消息和重置密码消息的重构,待处理模板卡片消息的icon_url
- Loading branch information
1 parent
a68bee6
commit fa877b9
Showing
7 changed files
with
461 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import base64 | ||
import io | ||
import functools | ||
|
||
import odoo | ||
from odoo import api, http, models, fields, SUPERUSER_ID, _ | ||
from odoo.modules import get_module_path, get_resource_path | ||
from odoo.http import request | ||
from odoo.addons.web.controllers.main import db_monodb, Binary | ||
from odoo.tools.mimetypes import guess_mimetype | ||
|
||
|
||
class WxworkBinary(Binary): | ||
"""[summary] | ||
获取方块Logo | ||
Args: | ||
Binary ([type]): [description] | ||
""" | ||
|
||
# @http.route( | ||
# [ | ||
# "/web/binary/wecom_message_logo", | ||
# "/wecom_message_logo", | ||
# "/wecom_message_logo.png", | ||
# ], | ||
# type="http", | ||
# auth="none", | ||
# cors="*", | ||
# ) | ||
@http.route( | ||
[ | ||
"/web/binary/wecom_message_logo", | ||
"/wecom_message_logo", | ||
"/wecom_message_logo.png", | ||
], | ||
type="http", | ||
auth="none", | ||
cors="*", | ||
) | ||
def company_wecom_message_web_logo(self, dbname=None, **kw): | ||
imgname = "wecom_message_logo" | ||
imgext = ".png" | ||
placeholder = functools.partial( | ||
get_resource_path, "web", "static", "src", "img" | ||
) | ||
uid = None | ||
if request.session.db: | ||
dbname = request.session.db | ||
uid = request.session.uid | ||
elif dbname is None: | ||
dbname = db_monodb() | ||
|
||
if not uid: | ||
uid = odoo.SUPERUSER_ID | ||
|
||
if not dbname: | ||
response = http.send_file(placeholder(imgname + imgext)) | ||
else: | ||
try: | ||
# create an empty registry | ||
registry = odoo.modules.registry.Registry(dbname) | ||
with registry.cursor() as cr: | ||
company = int(kw["company"]) if kw and kw.get("company") else False | ||
|
||
if company: | ||
cr.execute( | ||
"""SELECT wecom_message_logo_web, write_date | ||
FROM res_company | ||
WHERE id = %s | ||
""", | ||
(company,), | ||
) | ||
else: | ||
cr.execute( | ||
"""SELECT c.wecom_message_logo_web, c.write_date | ||
FROM res_users u | ||
LEFT JOIN res_company c | ||
ON c.id = u.company_id | ||
WHERE u.id = %s | ||
""", | ||
(uid,), | ||
) | ||
row = cr.fetchone() | ||
|
||
if row and row[0]: | ||
image_base64 = base64.b64decode(row[0]) | ||
image_data = io.BytesIO(image_base64) | ||
mimetype = guess_mimetype(image_base64, default="image/png") | ||
imgext = "." + mimetype.split("/")[1] | ||
if imgext == ".svg+xml": | ||
imgext = ".svg" | ||
response = http.send_file( | ||
image_data, | ||
filename=imgname + imgext, | ||
mimetype=mimetype, | ||
mtime=row[1], | ||
) | ||
else: | ||
response = http.send_file(placeholder("nologo.png")) | ||
except Exception: | ||
response = http.send_file(placeholder(imgname + imgext)) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.