示例#1
0
    def _get_default_image(self, partner_type, is_company, parent_id):
        if getattr(threading.currentThread(), 'testing', False) or self._context.get('install_mode'):
            return False

        colorize, img_path, image = False, False, False

        if partner_type in ['contact', 'other'] and parent_id:
            parent_image = self.browse(parent_id).image
            image = parent_image and parent_image.decode('base64') or None

        if not image and partner_type == 'invoice':
            img_path = get_module_resource('base', 'static/src/img', 'money.png')
        elif not image and partner_type == 'delivery':
            img_path = get_module_resource('base', 'static/src/img', 'truck.png')
        elif not image and is_company:
            img_path = get_module_resource('base', 'static/src/img', 'company_image.png')
        elif not image:
            img_path = get_module_resource('base', 'static/src/img', 'avatar.png')
            colorize = True

        if img_path:
            with open(img_path, 'rb') as f:
                image = f.read()
        if image and colorize:
            image = tools.image_colorize(image)

        return tools.image_resize_image_big(image.encode('base64'))
示例#2
0
    def _get_default_image(self, partner_type, is_company, parent_id):
        if getattr(threading.currentThread(), 'testing', False) or self._context.get('install_mode'):
            return False

        colorize, img_path, image_base64 = False, False, False

        if partner_type in ['other'] and parent_id:
            parent_image = self.browse(parent_id).image
            image_base64 = parent_image or None

        if not image_base64 and partner_type == 'invoice':
            img_path = get_module_resource('base', 'static/img', 'money.png')
        elif not image_base64 and partner_type == 'delivery':
            img_path = get_module_resource('base', 'static/img', 'truck.png')
        elif not image_base64 and is_company:
            img_path = get_module_resource('base', 'static/img', 'company_image.png')
        elif not image_base64:
            img_path = get_module_resource('base', 'static/img', 'avatar.png')
            colorize = True

        if img_path:
            with open(img_path, 'rb') as f:
                image_base64 = base64.b64encode(f.read())
        if image_base64 and colorize:
            image_base64 = tools.image_process(image_base64, colorize=True)

        return tools.image_process(image_base64, size=tools.IMAGE_BIG_SIZE)
示例#3
0
文件: module.py 项目: 0967697922/odoo
 def _get_icon_image(self):
     for module in self:
         module.icon_image = ''
         path = modules.get_module_resource(module.name, 'static', 'description', 'icon.png')
         if path:
             with tools.file_open(path, 'rb') as image_file:
                 module.icon_image = image_file.read().encode('base64')
示例#4
0
 def _default_image(self):
     image_path = modules.get_module_resource('im_livechat',
                                              'static/src/img',
                                              'default.png')
     return tools.image_process(base64.b64encode(
         open(image_path, 'rb').read()),
                                size=tools.IMAGE_BIG_SIZE)
示例#5
0
 def _get_default_image_path(self, vals):
     if vals.get("is_healthcare_service", False):
         return get_module_resource(
             "medical_administration_healtchare_service",
             "static/src/img",
             "healtchare-avatar.png",
         )
示例#6
0
 def _get_default_image_path(self, vals):
     if vals.get("is_practitioner", False):
         return get_module_resource(
             "medical_administration_practitioner",
             "static/src/img",
             "practitioner-avatar.png",
         )
示例#7
0
 def _get_desc(self):
     for module in self:
         if module.name and module.description:
             path = modules.get_module_resource(
                 module.name, "static/description/index.html")
             if path:
                 with tools.file_open(path, "rb") as desc_file:
                     doc = desc_file.read()
                     html = lxml.html.document_fromstring(doc)
                     for element, attribute, link, pos in html.iterlinks():
                         if (element.get("src")
                                 and "//" not in element.get("src")
                                 and "static/" not in element.get("src")):
                             element.set(
                                 "src",
                                 "/%s/static/description/%s" %
                                 (module.name, element.get("src")),
                             )
                     module.description_html = tools.html_sanitize(
                         lxml.html.tostring(html))
             else:
                 overrides = {
                     "embed_stylesheet": False,
                     "doctitle_xform": False,
                     "output_encoding": "unicode",
                     "xml_declaration": False,
                     "file_insertion_enabled": False,
                 }
                 output = publish_string(
                     source=module.description if not module.application
                     and module.description else "",
                     settings_overrides=overrides,
                     writer=MyWriter(),
                 )
                 module.description_html = tools.html_sanitize(output)
示例#8
0
文件: module.py 项目: thom-peele/odoo
 def _get_desc(self):
     for module in self:
         path = modules.get_module_resource(
             module.name, 'static/description/index.html')
         if path:
             with tools.file_open(path, 'rb') as desc_file:
                 doc = desc_file.read()
                 html = lxml.html.document_fromstring(doc)
                 for element, attribute, link, pos in html.iterlinks():
                     if element.get('src') and not '//' in element.get(
                             'src') and not 'static/' in element.get('src'):
                         element.set(
                             'src', "/%s/static/description/%s" %
                             (module.name, element.get('src')))
                 module.description_html = tools.html_sanitize(
                     lxml.html.tostring(html))
         else:
             overrides = {
                 'embed_stylesheet': False,
                 'doctitle_xform': False,
                 'output_encoding': 'unicode',
                 'xml_declaration': False,
             }
             output = publish_string(source=module.description or '',
                                     settings_overrides=overrides,
                                     writer=MyWriter())
             module.description_html = tools.html_sanitize(output)
示例#9
0
 def _default_image(self):
     image_path = get_module_resource(
         "enhanced_crud",
         "static/description",
         "enhanced_crud_screenshot.png",
     )
     return tools.image_resize_image_big(
         base64.b64encode(open(image_path, "rb").read()))
示例#10
0
    def _load_module_terms(self, modules, langs):
        """ Load PO files of the given modules for the given languages. """
        # make sure the given languages are active
        res_lang = self.env['res.lang'].sudo()
        for lang in langs:
            res_lang.load_lang(lang)
        # load i18n files
        for module_name in modules:
            modpath = get_module_path(module_name)
            if not modpath:
                continue
            for lang in langs:
                context = dict(self._context)
                lang_code = tools.get_iso_codes(lang)
                base_lang_code = None
                if '_' in lang_code:
                    base_lang_code = lang_code.split('_')[0]

                # Step 1: for sub-languages, load base language first (e.g. es_CL.po is loaded over es.po)
                if base_lang_code:
                    base_trans_file = get_module_resource(module_name, 'i18n', base_lang_code + '.po')
                    if base_trans_file:
                        _logger.info('module %s: loading base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(self._cr, base_trans_file, lang, verbose=False, module_name=module_name, context=context)
                        context['overwrite'] = True  # make sure the requested translation will override the base terms later

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = get_module_resource(module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info('module %s: loading extra base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(self._cr, base_trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
                        context['overwrite'] = True  # make sure the requested translation will override the base terms later

                # Step 2: then load the main translation file, possibly overriding the terms coming from the base language
                trans_file = get_module_resource(module_name, 'i18n', lang_code + '.po')
                if trans_file:
                    _logger.info('module %s: loading translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(self._cr, trans_file, lang, verbose=False, module_name=module_name, context=context)
                elif lang_code != 'en_US':
                    _logger.info('module %s: no translation for language %s', module_name, lang_code)

                trans_extra_file = get_module_resource(module_name, 'i18n_extra', lang_code + '.po')
                if trans_extra_file:
                    _logger.info('module %s: loading extra translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(self._cr, trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
        return True
示例#11
0
    def _get_default_image(self, partner_type, is_company, parent_id):

        if partner_type not in ['land','building']:
            return super(Partner, self)._get_default_image(partner_type, is_company, parent_id)


        if partner_type == 'land':
            img_path = get_module_resource('deltatech_property', 'static/src/img', 'land.png')
        else:
            img_path = get_module_resource('deltatech_property', 'static/src/img', 'building.png')

        with open(img_path, 'rb') as f:
            image = f.read()

        image = tools.image_colorize(image)

        return tools.image_resize_image_big(image.encode('base64'))
示例#12
0
    def load_module_terms(self, modules, langs):
        """ Load PO files of the given modules for the given languages. """
        # make sure the given languages are active
        res_lang = self.env['res.lang'].sudo()
        for lang in langs:
            res_lang.load_lang(lang)
        # load i18n files
        for module_name in modules:
            modpath = get_module_path(module_name)
            if not modpath:
                continue
            for lang in langs:
                context = dict(self._context)
                lang_code = tools.get_iso_codes(lang)
                base_lang_code = None
                if '_' in lang_code:
                    base_lang_code = lang_code.split('_')[0]

                # Step 1: for sub-languages, load base language first (e.g. es_CL.po is loaded over es.po)
                if base_lang_code:
                    base_trans_file = get_module_resource(module_name, 'i18n', base_lang_code + '.po')
                    if base_trans_file:
                        _logger.info('module %s: loading base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(self._cr, base_trans_file, lang, verbose=False, module_name=module_name, context=context)
                        context['overwrite'] = True  # make sure the requested translation will override the base terms later

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = get_module_resource(module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info('module %s: loading extra base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(self._cr, base_trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
                        context['overwrite'] = True  # make sure the requested translation will override the base terms later

                # Step 2: then load the main translation file, possibly overriding the terms coming from the base language
                trans_file = get_module_resource(module_name, 'i18n', lang_code + '.po')
                if trans_file:
                    _logger.info('module %s: loading translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(self._cr, trans_file, lang, verbose=False, module_name=module_name, context=context)
                elif lang_code != 'en_US':
                    _logger.info('module %s: no translation for language %s', module_name, lang_code)

                trans_extra_file = get_module_resource(module_name, 'i18n_extra', lang_code + '.po')
                if trans_extra_file:
                    _logger.info('module %s: loading extra translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(self._cr, trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
        return True
示例#13
0
 def _get_default_image_path(self, vals):
     res = super()._get_default_image_path(vals)
     if res:
         return res
     image_path = get_module_resource(
         'clv_family_aux', 'static/src/img', 'family_aux-avatar.png',
     )
     return image_path
示例#14
0
 def _default_image(self):
     '''Method to get default Image'''
     image_path = get_module_resource('hr', 'static/src/img',
                                      'default_image.png')
     image_process = ImageProcess(
         base64.b64encode(open(image_path, 'rb').read()))
     return image_process.resize(max_width=400,
                                 max_height=600).image_base64()
    def font_absolute_path(self):
        """Will get the ocrb font absolute path

        :return: path to the font
        """
        path = get_module_resource('l10n_ch_payment_slip', 'static', 'src',
                                   'font', 'ocrbb.ttf')
        return path
示例#16
0
 def getFile(self, filename):
     path = get_module_resource('l10n_it_fatturapa_in', 'tests', 'data',
                                filename)
     with open(path, 'rb') as test_data:
         with tempfile.TemporaryFile() as out:
             base64.encode(test_data, out)
             out.seek(0)
             return path, out.read()
示例#17
0
 def _get_icon_image(self):
     for module in self:
         module.icon_image = ''
         path = modules.get_module_resource(module.name, 'static',
                                            'description', 'icon.png')
         if path:
             with tools.file_open(path, 'rb') as image_file:
                 module.icon_image = image_file.read().encode('base64')
 def _compute_demo_image(self):
     for record in self:
         path = get_module_resource(record.name, 'static', 'description', 'demo_image.png')
         if path:
             image_file = tools.file_open(path, 'rb')
             try:
                 record.demo_image = image_file.read().encode('base64')
             finally:
                 image_file.close()
示例#19
0
def get_preview_images(datas, is_image=True):
    resized_images = {}
    if is_image:
        try:
            resized_images = get_resized_images(datas)
        except IOError:
            img_path = get_module_resource('web', 'static/src/img', 'placeholder.png')
            if img_path:
                with open(img_path, 'rb') as f:
                    return get_resized_images(base64.b64encode(f.read()))
    else:
        img_path = get_module_resource('lighting', 'static/src/img', 'doc.png')
        if img_path:
            with open(img_path, 'rb') as f:
                resized_images = get_resized_images(
                    base64.b64encode(f.read()))

    return resized_images
示例#20
0
 def _onchange_s_window_disposition(self):
     if self.s_window_disposition:
         image_name = ("enhanced_crud_screenshot.png"
                       if self.s_window_disposition == "new" else
                       "window_disposition_current.png")
         image_path = get_module_resource("enhanced_crud",
                                          "static/description", image_name)
         self.img_window_disposition = tools.image_resize_image_big(
             base64.b64encode(open(image_path, "rb").read()))
示例#21
0
 def getFile(self, filename, module_name=None):
     if module_name is None:
         module_name = "l10n_it_fatturapa_in"
     path = get_module_resource(module_name, "tests", "data", filename)
     with open(path, "rb") as test_data:
         with tempfile.TemporaryFile() as out:
             base64.encode(test_data, out)
             out.seek(0)
             return path, out.read()
示例#22
0
    def get_image(self, vals={}):
        image = None
        if vals:
            is_company = vals
        else:
            is_company = self.is_company
        if is_company:
            img_path = get_module_resource('base', 'static/img',
                                           'company_image.png')
        else:
            img_path = get_module_resource('base', 'static/img', 'avatar.png')
            # colorize = True

        if img_path:
            with open(img_path, 'rb') as f:
                image = f.read()

        if image:
            return tools.image_resize_image_big(base64.b64encode(image))
示例#23
0
 def onchange_default_shipping(self):
     if self.default_shipping_address:
         image = modules.get_module_resource('customer_area',
                                             'static/src/img/',
                                             'icon-fav.png')
         with open(image, "rb") as image_file:
             encoded_string = base64.b64encode(image_file.read())
             self.image = encoded_string
     else:
         self.image = False
示例#24
0
 def _get_default_image(self):
     image = False
     img_path = get_module_resource('berp_usuarios', 'static/src/img',
                                    'avatar.png')
     if img_path:
         with open(img_path, 'rb') as f:
             image = f.read()
     if image:
         image = tools.image_colorize(image)
     return tools.image_resize_image_big(base64.b64encode(image))
示例#25
0
 def get_fattura_elettronica_preview(self):
     xsl_path = get_module_resource(
         'l10n_it_fatturapa', 'data', 'fatturaordinaria_v1.2.1.xsl')
     xslt = ET.parse(xsl_path)
     xml_string = self.get_xml_string()
     xml_file = BytesIO(xml_string)
     dom = ET.parse(xml_file)
     transform = ET.XSLT(xslt)
     newdom = transform(dom)
     return ET.tostring(newdom, pretty_print=True)
示例#26
0
    def import_file_pain002(self):
        test_file_path = get_module_resource('l10n_ch_import_pain002',
                                             'test_files',
                                             'pain002p-rejected.xml')

        file_to_import = open(test_file_path, 'r')
        data = file_to_import.read()
        data = data.replace("\n", "")

        self.account_pain002.parse(data)
示例#27
0
 def read_image(self, path):
     if not path:
         return False
     path_info = path.split(',')
     icon_path = get_module_resource(path_info[0], path_info[1])
     icon_image = False
     if icon_path:
         with tools.file_open(icon_path, 'rb') as icon_file:
             icon_image = base64.encodestring(icon_file.read())
     return icon_image
示例#28
0
文件: ir_ui_menu.py 项目: barsi/odoo
 def read_image(self, path):
     if not path:
         return False
     path_info = path.split(',')
     icon_path = get_module_resource(path_info[0], path_info[1])
     icon_image = False
     if icon_path:
         with tools.file_open(icon_path, 'rb') as icon_file:
             icon_image = base64.encodestring(icon_file.read())
     return icon_image
示例#29
0
    def button_generate(self):
        t0 = time.time()
        m0 = memory_info()
        self.date_generated = fields.Datetime.now()
        auditfile_template = self._get_auditfile_template()
        xml = self.env['ir.ui.view'].render_template(
            auditfile_template,
            values={
                'self': self,
            },
        )
        # the following is dealing with the fact that qweb templates don't like
        # namespaces, but we need the correct namespaces for validation
        xml = xml.decode().strip().replace(
            '<auditfile>', '<?xml version="1.0" encoding="UTF-8"?>'
            '<auditfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
            'xmlns="http://www.auditfiles.nl/XAF/3.2">', 1)

        filename = self.name + '.xaf'
        tmpdir = mkdtemp()
        auditfile = os.path.join(tmpdir, filename)
        archivedir = mkdtemp()
        archive = os.path.join(archivedir, filename)
        try:
            with open(auditfile, 'w+') as tmphandle:
                tmphandle.write(xml)
            del xml

            # Validate the generated XML
            xsd = etree.XMLParser(schema=etree.XMLSchema(
                etree.parse(
                    open(
                        modules.get_module_resource(
                            'l10n_nl_xaf_auditfile_export', 'data',
                            'XmlAuditfileFinancieel3.2.xsd')))))
            etree.parse(auditfile, parser=xsd)
            del xsd

            # Store in compressed format on the auditfile record
            zip_path = shutil.make_archive(archive,
                                           'zip',
                                           tmpdir,
                                           verbose=True)
            with open(zip_path, 'rb') as auditfile_zip:
                self.auditfile = base64.b64encode(auditfile_zip.read())
            logging.getLogger(__name__).debug(
                'Created an auditfile in %ss, using %sk memory',
                int(time.time() - t0), (memory_info() - m0) / 1024)

        except etree.XMLSyntaxError as e:
            logging.getLogger(__name__).error(e)
            self.message_post(body=e)
        finally:
            shutil.rmtree(tmpdir)
            shutil.rmtree(archivedir)
示例#30
0
文件: module.py 项目: microcom/odoo
 def _get_icon_image(self):
     for module in self:
         module.icon_image = ''
         if module.icon:
             path_parts = module.icon.split('/')
             path = modules.get_module_resource(path_parts[1], *path_parts[2:])
         else:
             path = modules.get_module_icon(module.name)
         if path:
             with tools.file_open(path, 'rb') as image_file:
                 module.icon_image = image_file.read().encode('base64')
示例#31
0
    def _get_default_image(self, is_company, colorize=False):
        img_path = get_module_resource('sistemerp_ereport_template',
                                       'static/src/img', 'avatar.png')
        with open(img_path, 'rb') as f:
            image = f.read()

        # colorize user avatars
        if not is_company:
            image = tools.image_colorize(image)

        return tools.image_resize_image_big(base64.b64encode(image))
示例#32
0
文件: module.py 项目: Badeea-center/1
 def _get_icon_image(self):
     for module in self:
         module.icon_image = ''
         if module.icon:
             path_parts = module.icon.split('/')
             path = modules.get_module_resource(path_parts[1], *path_parts[2:])
         else:
             path = modules.module.get_module_icon(module.name)
         if path:
             with tools.file_open(path, 'rb') as image_file:
                 module.icon_image = base64.b64encode(image_file.read())
    def image_absolute_path(self, file_name):
        """Will get image absolute path

        :param file_name: name of image

        :return: image path
        :rtype: str
        """
        path = get_module_resource('l10n_ch_payment_slip', 'static', 'src',
                                   'img', file_name)
        return path
    def test_get_default_image_path_no_super_result_none(self, super_mock):
        """It should return male path if result falsy and gender unspecified"""
        super_mock.return_value = None
        result = self.practitioner_model._get_default_image_path({})

        expected = modules.get_module_resource(
            'medical_practitioner',
            'static/src/img',
            'practitioner-male-avatar.png',
        )
        self.assertEquals(result, expected)
 def get_demo_images(self):
     for record in self:
         res = {}
         img_path = get_module_resource(record.name, 'static', 'description', 'demo')
         if img_path:
             (_, _, filenames) = walk(img_path).next()
             for file_name in filenames:
                 full_name = os.path.join(img_path, file_name)
                 with tools.file_open(full_name, 'rb') as image_file:
                     res[file_name] = image_file.read().encode('base64')
             return res
    def _action_create_expense(self, values, sample_number):
        fallback_employee = self.env['hr.employee'].search(
            [], limit=1) or self.env['hr.employee'].create(
                {
                    'name': _('Sample Employee'),
                    'company_id': self.env.company.id,
                })
        product = self.env.ref('hr_expense.product_product_fixed_cost')

        # 3/ Compute the line values
        expense_line_values = {
            'name': _("Sample Receipt: %s", values['name']),
            'product_id': product.id,
            'unit_amount': values['amount'],
            'quantity': 1.0,
            'date': values['date'],
            'tax_ids': [(5, 0, 0)],
            'sample': True,
            'employee_id': self.env.user.employee_id.id
            or fallback_employee.id,
        }

        # 4/ Ensure we have a jounal
        journal_id = self.env['hr.expense.sheet']._default_journal_id(
        ) or self.env['account.journal'].create(
            {
                'type': 'purchase',
                'company_id': self.env.company.id,
                'name': 'Sample Journal',
                'code': 'SAMPLE_P',
            }).id

        # 5/ Create the expense
        expense = self.env['hr.expense'].create(expense_line_values)

        # 6/ Link the attachment
        image_path = get_module_resource('hr_expense_extract', 'static/img',
                                         'sample_%s.jpeg' % sample_number)
        image = base64.b64encode(open(image_path, 'rb').read())
        self.env['ir.attachment'].create({
            'name': 'sample_receipt.jpeg',
            'res_id': expense.id,
            'res_model': 'hr.expense',
            'datas': image,
            'type': 'binary',
        })

        return {
            'name': expense.name,
            'type': 'ir.actions.act_window',
            'res_model': 'hr.expense',
            'view_mode': 'form',
            'res_id': expense.id,
        }
示例#37
0
文件: main.py 项目: Tecnativa/odoo
 def _get_default_avatar(self, field, headers, width, height):
     img_path = modules.get_module_resource('web', 'static/src/img', 'placeholder.png')
     with open(img_path, 'rb') as f:
         image = f.read()
     content = base64.b64encode(image)
     dictheaders = dict(headers) if headers else {}
     dictheaders['Content-Type'] = 'image/png'
     if not (width or height):
         suffix = field.split('_')[-1] if '_' in field else 'large'
         if suffix in ('small', 'medium', 'large', 'big'):
             content = getattr(tools, 'image_resize_image_%s' % suffix)(content)
     return content
示例#38
0
 def get_demo_images(self):
     self.ensure_one()
     demo_images = self.demo_images and self.demo_images.split(',')
     res = []
     mod_path = get_module_resource(self.name)
     for image_name in demo_images:
         full_name = os.path.join(mod_path, image_name)
         try:
             with tools.file_open(full_name, 'rb') as image_file:
                 res.append((image_name, image_file.read().encode('base64')))
         except:
             pass
     return res
示例#39
0
    def _get_default_image(self):
        if getattr(threading.currentThread(), 'testing', False) or self._context.get('install_mode'):
            return False
        colorize, img_path, image = False, False, False
        img_path = get_module_resource('library', 'static/description/img', 'dummy.png')
        colorize = True

        if img_path:
            with open(img_path, 'rb') as f:
                image = f.read()
        if image and colorize:
            image = tools.image_colorize(image)
        return tools.image_resize_image_big(base64.b64encode(image))
示例#40
0
文件: main.py 项目: 10537/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=SUPERUSER_ID))

        if not content:
            img_path = modules.get_module_resource('web', 'static/src/img', 'placeholder.png')
            with open(img_path, 'rb') as f:
                image = f.read()
            content = base64.b64encode(image)
        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
示例#41
0
文件: module.py 项目: microcom/odoo
 def _get_desc(self):
     for module in self:
         path = modules.get_module_resource(module.name, 'static/description/index.html')
         if path:
             with tools.file_open(path, 'rb') as desc_file:
                 doc = desc_file.read()
                 html = lxml.html.document_fromstring(doc)
                 for element, attribute, link, pos in html.iterlinks():
                     if element.get('src') and not '//' in element.get('src') and not 'static/' in element.get('src'):
                         element.set('src', "/%s/static/description/%s" % (module.name, element.get('src')))
                 module.description_html = tools.html_sanitize(lxml.html.tostring(html))
         else:
             overrides = {
                 'embed_stylesheet': False,
                 'doctitle_xform': False,
                 'output_encoding': 'unicode',
                 'xml_declaration': False,
             }
             output = publish_string(source=module.description or '', settings_overrides=overrides, writer=MyWriter())
             module.description_html = tools.html_sanitize(output)
示例#42
0
文件: interface.py 项目: ADS101/odoo
    def post_process_xml_data(self, cr, uid, xml, context=None):
        # find the position of the 3rd tag
        # (skip the <?xml ...?> and the "root" tag)
        iter = re.finditer('<[^>]*>', xml)
        i = iter.next()
        i = iter.next()
        pos_xml = i.end()

        doc = print_xml.document(cr, uid, {}, {})
        tmpl_path = get_module_resource('base', 'report', 'corporate_defaults.xml')
        doc.parse(tmpl_path, [uid], 'res.users', context)
        corporate_header = doc.xml_get()
        doc.close()

        # find the position of the tag after the <?xml ...?> tag
        iter = re.finditer('<[^>]*>', corporate_header)
        i = iter.next()
        pos_header = i.end()

        return xml[:pos_xml] + corporate_header[pos_header:] + xml[pos_xml:]
示例#43
0
文件: main.py 项目: halybang/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=SUPERUSER_ID),
        )

        if not content:
            img_path = 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
示例#44
0
文件: forum.py 项目: qq470647251/odoo
 def _get_default_faq(self):
     fname = modules.get_module_resource('website_forum', 'data', 'forum_default_faq.html')
     with open(fname, 'r') as f:
         return f.read()
     return False
示例#45
0
文件: main.py 项目: datenbetrieb/odoo
 def _get_default_avatar(self):
     img_path = modules.get_module_resource('web', 'static/src/img', 'placeholder.png')
     with open(img_path, 'rb') as f:
         return base64.b64encode(f.read())
示例#46
0
 def qweb_test_file_path(cls):
     return os.path.dirname(get_module_resource('web', 'static', 'lib', 'qweb', 'qweb2.js'))
示例#47
0
 def _default_image(self):
     image_path = modules.get_module_resource('im_livechat', 'static/src/img', 'default.png')
     return tools.image_process(base64.b64encode(open(image_path, 'rb').read()), size=tools.IMAGE_BIG_SIZE)
示例#48
0
文件: forum.py 项目: pniederlag/odoo
 def _get_default_faq(self):
     fname = modules.get_module_resource("website_forum", "data", "forum_default_faq.html")
     with open(fname, "r") as f:
         return f.read()
     return False
示例#49
0
 def _default_image(self):
     image_path = modules.get_module_resource('im_livechat', 'static/src/img', 'default.png')
     return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
示例#50
0
 def _get_default_image(self):
     image_path = modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png')
     return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))