odoo16处理未登录无法访问附件外链问题

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : raw_url.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2023/8/21

from odoo import http
from odoo.exceptions import AccessError, UserError
from odoo.http import request, Response
from odoo.tools import file_open, file_path, replace_exceptions
from odoo.tools.image import image_guess_size_from_field_name
from odoo.addons.web.controllers.binary import Binary


class RawUrl(Binary):
    def use_admin(self):
        admin_user = request.env.ref('base.user_admin')
        http.request.env.uid = admin_user.id
        http.request.env.clear()

    @http.route(['/web/raw',
                 '/web/raw/<string:xmlid>',
                 '/web/raw/<string:xmlid>/<string:filename>',
                 '/web/raw/<int:id>',
                 '/web/raw/<int:id>/<string:filename>',
                 '/web/raw/<string:model>/<int:id>/<string:field>',
                 '/web/raw/<string:model>/<int:id>/<string:field>/<string:filename>'], type='http', auth="public")
    # pylint: disable=redefined-builtin,invalid-name
    def content_common1(self, xmlid=None, model='ir.attachment', id=None, field='raw',
                        filename=None, filename_field='name', mimetype=None, unique=False,
                        download=False, access_token=None, nocache=False):
        self.use_admin()
        return super().content_common(xmlid=xmlid, model=model, id=id, field=field,
                                      filename=filename, filename_field=filename_field,
                                      mimetype=mimetype, unique=unique, download=download,
                                      access_token=access_token, nocache=nocache)

    @http.route(['/web/images',
                 '/web/images/<string:xmlid>',
                 '/web/images/<string:xmlid>/<string:filename>',
                 '/web/images/<string:xmlid>/<int:width>x<int:height>',
                 '/web/images/<string:xmlid>/<int:width>x<int:height>/<string:filename>',
                 '/web/images/<string:model>/<int:id>/<string:field>',
                 '/web/images/<string:model>/<int:id>/<string:field>/<string:filename>',
                 '/web/images/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>',
                 '/web/images/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>/<string:filename>',
                 '/web/images/<int:id>',
                 '/web/images/<int:id>/<string:filename>',
                 '/web/images/<int:id>/<int:width>x<int:height>',
                 '/web/images/<int:id>/<int:width>x<int:height>/<string:filename>',
                 '/web/images/<int:id>-<string:unique>',
                 '/web/images/<int:id>-<string:unique>/<string:filename>',
                 '/web/images/<int:id>-<string:unique>/<int:width>x<int:height>',
                 '/web/images/<int:id>-<string:unique>/<int:width>x<int:height>/<string:filename>'], type='http',
                auth="public")
    # pylint: disable=redefined-builtin,invalid-name
    def content_image1(self, xmlid=None, model='ir.attachment', id=None, field='raw',
                       filename_field='name', filename=None, mimetype=None, unique=False,
                       download=False, width=0, height=0, crop=False, access_token=None,
                       nocache=False):
        self.use_admin()
        return super().content_image(xmlid=xmlid, model=model, id=id, field=field,
                                     filename_field=filename_field,
                                     filename=filename,
                                     mimetype=mimetype, unique=unique, download=download,
                                     width=width, height=height, crop=crop,
                                     access_token=access_token, nocache=nocache)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值