コード例 #1
0
 def avatar(self, res_model, res_id, partner_id):
     content = None
     if res_model in request.env:
         try:
             # if the current user has access to the document, get the partner avatar as sudo()
             request.env[res_model].browse(res_id).check_access_rule('read')
             if partner_id in request.env[res_model].browse(res_id).sudo(
             ).exists().message_ids.mapped('author_id').ids:
                 status, headers, content = binary_content(
                     model='res.partner',
                     id=partner_id,
                     field='image_medium',
                     default_mimetype='image/png',
                     env=request.env(user=openerp.SUPERUSER_ID))
                 if status == 304:
                     return werkzeug.wrappers.Response(status=304)
         except AccessError:
             pass
     if content:
         image_base64 = base64.b64decode(content)
     else:
         binary = Binary()
         image_base64 = binary.placeholder(
             image='placeholder.png'
         )  # could return (contenttype, content) in master
         headers = binary.force_contenttype(headers,
                                            contenttype='image/png')
     headers.append(('Content-Length', len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #2
0
ファイル: main.py プロジェクト: zbqf109/goodo
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=getattr(asset, ext)().id, unique=asset.checksum)
     content_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
コード例 #3
0
ファイル: main.py プロジェクト: lonelyleaves/odoo
 def avatar(self, res_model, res_id, partner_id):
     headers = [[("Content-Type", "image/png")]]
     content = "R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="  # default image is one white pixel
     if res_model in request.env:
         try:
             # if the current user has access to the document, get the partner avatar as sudo()
             request.env[res_model].browse(res_id).check_access_rule("read")
             if (
                 partner_id
                 in request.env[res_model].browse(res_id).sudo().exists().message_ids.mapped("author_id").ids
             ):
                 status, headers, content = binary_content(
                     model="res.partner",
                     id=partner_id,
                     field="image_medium",
                     default_mimetype="image/png",
                     env=request.env(user=openerp.SUPERUSER_ID),
                 )
                 if status == 304:
                     return werkzeug.wrappers.Response(status=304)
         except AccessError:
             pass
     image_base64 = base64.b64decode(content)
     headers.append(("Content-Length", len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #4
0
ファイル: main.py プロジェクト: ws-mps/odoo
 def avatar(self, res_model, res_id, partner_id):
     headers = [[('Content-Type', 'image/png')]]
     content = 'R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='  # default image is one white pixel
     if res_model in request.env:
         try:
             # if the current user has access to the document, get the partner avatar as sudo()
             request.env[res_model].browse(res_id).check_access_rule('read')
             if partner_id in request.env[res_model].browse(res_id).sudo(
             ).exists().message_ids.mapped('author_id').ids:
                 status, headers, _content = binary_content(
                     model='res.partner',
                     id=partner_id,
                     field='image_medium',
                     default_mimetype='image/png',
                     env=request.env(user=openerp.SUPERUSER_ID))
                 # binary content return an empty string and not a placeholder if obj[field] is False
                 if _content != '':
                     content = _content
                 if status == 304:
                     return werkzeug.wrappers.Response(status=304)
         except AccessError:
             pass
     image_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #5
0
ファイル: main.py プロジェクト: zdlll/odoo
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=getattr(asset, ext)().id,
                                               unique=asset.checksum)
     content_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
コード例 #6
0
ファイル: main.py プロジェクト: QinerTech/QinerApps
 def user_avatar(self, user_id=0, **post):
     status, headers, content = binary_content(model='res.users', id=user_id, field='image', default_mimetype='image/png', env=request.env(user=openerp.SUPERUSER_ID))
     if status == 304:
         return werkzeug.wrappers.Response(status=304)
     image_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #7
0
 def user_avatar(self, user_id=0, **post):
     status, headers, content = binary_content(model='res.users', id=user_id, field='image', default_mimetype='image/png', env=request.env(openerp.SUPERUSER_ID))
     if status == 304:
         return werkzeug.wrappers.Response(status=304)
     image_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #8
0
ファイル: main.py プロジェクト: vmlf01/odoo
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     mock_attachment = getattr(asset, ext)()
     if isinstance(mock_attachment, list):  # suppose that CSS asset will not required to be split in pages
         mock_attachment = mock_attachment[0]
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=mock_attachment.id, unique=asset.checksum)
     content_base64 = base64.b64decode(content) if content else ''
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
コード例 #9
0
ファイル: main.py プロジェクト: vak0160/odoo-1
 def livechat_lib(self, ext, **kwargs):
     asset = AssetsBundle("im_livechat.external_lib")
     mock_attachment = getattr(asset, ext)()
     if isinstance(mock_attachment, list):  # suppose that CSS asset will not required to be split in pages
         mock_attachment = mock_attachment[0]
     # can't use /web/content directly because we don't have attachment ids (attachments must be created)
     status, headers, content = binary_content(id=mock_attachment.id, unique=asset.checksum)
     content_base64 = base64.b64decode(content) if content else ''
     headers.append(('Content-Length', len(content_base64)))
     return request.make_response(content_base64, headers)
コード例 #10
0
ファイル: main.py プロジェクト: maugzuni/odoo
    def livechat_lib(self, ext, **kwargs):
        # _get_asset return the bundle html code (script and link list) but we want to use the attachment content
        xmlid = 'im_livechat.external_lib'
        files, remains = request.registry["ir.qweb"]._get_asset_content(request.cr, request.uid, xmlid, request.context)
        asset = AssetsBundle(xmlid, files, remains)

        mock_attachment = getattr(asset, ext)()
        if isinstance(mock_attachment, list):  # suppose that CSS asset will not required to be split in pages
            mock_attachment = mock_attachment[0]
        # can't use /web/content directly because we don't have attachment ids (attachments must be created)
        status, headers, content = binary_content(id=mock_attachment.id, unique=asset.checksum)
        content_base64 = base64.b64decode(content) if content else ''
        headers.append(('Content-Length', len(content_base64)))
        return request.make_response(content_base64, headers)
コード例 #11
0
ファイル: main.py プロジェクト: AntonioMalatesta/odoo
    def user_avatar(self, user_id=0, **post):
        status, headers, content = binary_content(model='res.users', id=user_id, field='image', default_mimetype='image/png', env=request.env(user=openerp.SUPERUSER_ID))

        if not content:
            img_path = openerp.modules.get_module_resource('web', 'static/src/img', 'placeholder.png')
            with open(img_path, 'rb') as f:
                image = f.read()
            content = image.encode('base64')
        if status == 304:
            return werkzeug.wrappers.Response(status=304)
        image_base64 = base64.b64decode(content)
        headers.append(('Content-Length', len(image_base64)))
        response = request.make_response(image_base64, headers)
        response.status = str(status)
        return response
コード例 #12
0
ファイル: main.py プロジェクト: digitalerp/odoo
    def user_avatar(self, user_id=0, **post):
        status, headers, content = binary_content(model='res.users', id=user_id, field='image_medium', default_mimetype='image/png', env=request.env(user=openerp.SUPERUSER_ID))

        if not content:
            img_path = openerp.modules.get_module_resource('web', 'static/src/img', 'placeholder.png')
            with open(img_path, 'rb') as f:
                image = f.read()
            content = image.encode('base64')
        if status == 304:
            return werkzeug.wrappers.Response(status=304)
        image_base64 = base64.b64decode(content)
        headers.append(('Content-Length', len(image_base64)))
        response = request.make_response(image_base64, headers)
        response.status = str(status)
        return response
コード例 #13
0
ファイル: main.py プロジェクト: ws-mps/odoo
    def livechat_lib(self, ext, **kwargs):
        # _get_asset return the bundle html code (script and link list) but we want to use the attachment content
        xmlid = 'im_livechat.external_lib'
        files, remains = request.env["ir.qweb"]._get_asset_content(
            xmlid, options=request.context)
        asset = AssetsBundle(xmlid, files, remains)

        mock_attachment = getattr(asset, ext)()
        if isinstance(
                mock_attachment, list
        ):  # suppose that CSS asset will not required to be split in pages
            mock_attachment = mock_attachment[0]
        # can't use /web/content directly because we don't have attachment ids (attachments must be created)
        status, headers, content = binary_content(id=mock_attachment.id,
                                                  unique=asset.checksum)
        content_base64 = base64.b64decode(content) if content else ''
        headers.append(('Content-Length', len(content_base64)))
        return request.make_response(content_base64, headers)
コード例 #14
0
ファイル: main.py プロジェクト: 0967697922/odoo
 def avatar(self, res_model, res_id, partner_id):
     headers = [[('Content-Type', 'image/png')]]
     content = 'R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='  # default image is one white pixel
     if res_model in request.env:
         try:
             # if the current user has access to the document, get the partner avatar as sudo()
             request.env[res_model].browse(res_id).check_access_rule('read')
             if partner_id in request.env[res_model].browse(res_id).sudo().exists().message_ids.mapped('author_id').ids:
                 status, headers, _content = binary_content(model='res.partner', id=partner_id, field='image_medium', default_mimetype='image/png', env=request.env(user=openerp.SUPERUSER_ID))
                 # binary content return an empty string and not a placeholder if obj[field] is False
                 if _content != '':
                     content = _content
                 if status == 304:
                     return werkzeug.wrappers.Response(status=304)
         except AccessError:
             pass
     image_base64 = base64.b64decode(content)
     headers.append(('Content-Length', len(image_base64)))
     response = request.make_response(image_base64, headers)
     response.status = str(status)
     return response
コード例 #15
0
ファイル: main.py プロジェクト: paimeykhuig/odoo
    def user_avatar(self, user_id=0, **post):
        status, headers, content = binary_content(
            model="res.users",
            id=user_id,
            field="image",
            default_mimetype="image/png",
            env=request.env(user=openerp.SUPERUSER_ID),
        )

        if not content:
            img_path = openerp.modules.get_module_resource("web", "static/src/img", "placeholder.png")
            with open(img_path, "rb") as f:
                image = f.read()
            content = image.encode("base64")
        if status == 304:
            return werkzeug.wrappers.Response(status=304)
        image_base64 = base64.b64decode(content)
        headers.append(("Content-Length", len(image_base64)))
        response = request.make_response(image_base64, headers)
        response.status = str(status)
        return response
コード例 #16
0
    def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0):
        status, headers, content = binary_content(xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype, default_mimetype='image/png')
        if status == 403:# This allows chat to load an image instead of nothing in Corebook Website Chat (loads corebook logo)
            return werkzeug.utils.redirect('https://s3-us-west-1.amazonaws.com/cbkpublic/images/56155c7e7f54fd584df8cbc1.png', code=301)
        if status == 304:
            return werkzeug.wrappers.Response(status=304, headers=headers)
        elif status == 301:
            return werkzeug.utils.redirect(content, code=301)
        elif status != 200 and download:
            return request.not_found()

        if content and (width or height):
            # resize maximum 500*500
            if width > 500:
                width = 500
            if height > 500:
                height = 500
            content = openerp.tools.image_resize_image(base64_source=content, size=(width or None, height or None), encoding='base64', filetype='PNG')

        image_base64 = content and base64.b64decode(content) or self.placeholder()
        headers.append(('Content-Length', len(image_base64)))
        response = request.make_response(image_base64, headers)
        response.status_code = status
        return response