#!/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)
odoo16处理未登录无法访问附件外链问题
于 2023-08-21 14:33:27 首次发布