예제 #1
0
    def test_static_misordered_modules(self):
        self.asset_paths.reverse()
        with self.assertRaises(ValueError) as ve:
            HomeStaticTemplateHelpers.get_qweb_templates(
                addons=self._get_module_names(), debug=True)

        self.assertEqual(
            str(ve.exception),
            'Module module_1 not loaded or inexistent, or templates of addon being loaded (module_2) are misordered'
        )
예제 #2
0
    def _prepare_project_sharing_session_info(self, project, task=None):
        session_info = request.env['ir.http'].session_info()
        user_context = dict(request.env.context) if request.session.uid else {}
        mods = conf.server_wide_modules or []
        qweb_checksum = HomeStaticTemplateHelpers.get_qweb_templates_checksum(
            debug=request.session.debug, bundle="project.assets_qweb")
        lang = user_context.get("lang")
        translation_hash = request.env[
            'ir.translation'].get_web_translations_hash(mods, lang)
        cache_hashes = {
            "qweb": qweb_checksum,
            "translations": translation_hash,
        }

        project_company = project.company_id
        session_info.update(
            cache_hashes=cache_hashes,
            action_name='project.project_sharing_project_task_action',
            project_id=project.id,
            user_companies={
                'current_company': project_company.id,
                'allowed_companies': {
                    project_company.id: {
                        'id': project_company.id,
                        'name': project_company.name,
                    },
                },
            },
            # FIXME: See if we prefer to give only the currency that the portal user just need to see the correct information in project sharing
            currencies=request.env['ir.http'].get_currencies(),
        )
        if task:
            session_info[
                'open_task_action'] = task.action_project_sharing_open_task()
        return session_info
예제 #3
0
    def test_static_inheritance_01(self):
        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1" random-attr="gloria">
                    <div>At first I was afraid</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
                <t t-name="template_1_2">
                    <div>And I grew strong</div>
                    <div>And I learned how to get along</div>
                </t>
                <form t-name="template_2_1" random-attr="gloria">
                    <div>At first I was afraid</div>
                    <div>I was petrified</div>
                    <div>But then I spent so many nights thinking how you did me wrong</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
                <div t-name="template_2_2">
                    <div>And I learned how to get along</div>
                </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #4
0
    def test_replace_in_debug_mode(self):
        """
        Replacing a template's meta definition in place doesn't keep the original attrs of the template
        """
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1" random-attr="gloria">
                        <div>At first I was afraid</div>
                    </form>
                    <t t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="extension">
                        <xpath expr="." position="replace">
                            <div overriden-attr="overriden">And I grew strong</div>
                        </xpath>
                    </t>
                </templates>
                """,
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <div overriden-attr="overriden" t-name="template_1_1">
                    And I grew strong
                </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #5
0
    def test_static_misordered_templates(self):
        self.template_files['module_2_file_1'] = b"""
            <templates id="template" xml:space="preserve">
                <form t-name="template_2_1" t-inherit="module_2.template_2_2" t-inherit-mode="primary">
                    <xpath expr="//div[1]" position="after">
                        <div>I was petrified</div>
                    </xpath>
                </form>
                <div t-name="template_2_2">
                    <div>And I learned how to get along</div>
                </div>
            </templates>
        """
        with self.assertRaises(ValueError) as ve:
            HomeStaticTemplateHelpers.get_qweb_templates(
                addons=self._get_module_names(), debug=True)

        self.assertEqual(
            str(ve.exception),
            'No template found to inherit from. Module module_2 and template name template_2_2'
        )
예제 #6
0
    def test_sibling_extension(self):
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
            ('module_2_file_1', 'module_2', 'bundle_1'),
            ('module_3_file_1', 'module_3', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b'''
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1">
                        <div>I am a man of constant sorrow</div>
                        <div>I've seen trouble all my days</div>
                    </form>
                </templates>
            ''',
            'module_2_file_1':
            b'''
                <templates id="template" xml:space="preserve">
                    <form t-name="template_2_1" t-inherit="module_1.template_1_1" t-inherit-mode="extension">
                        <xpath expr="//div[1]" position="after">
                            <div>In constant sorrow all through his days</div>
                        </xpath>
                    </form>
                </templates>
            ''',
            'module_3_file_1':
            b'''
                <templates id="template" xml:space="preserve">
                    <form t-name="template_3_1" t-inherit="module_1.template_1_1" t-inherit-mode="extension">
                        <xpath expr="//div[2]" position="after">
                            <div>Oh Brother !</div>
                        </xpath>
                    </form>
                </templates>
            '''
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1">
                    <div>I am a man of constant sorrow</div>
                    <div>In constant sorrow all through his days</div>
                    <div>Oh Brother !</div>
                    <div>I've seen trouble all my days</div>
                </form>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #7
0
    def test_static_templates_treatment_linearity(self):
        # With 2500 templates for starters
        nMod, nFilePerMod, nTemplatePerFile = 50, 5, 10
        self._sick_script(nMod, nFilePerMod, nTemplatePerFile)

        before = datetime.now()
        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        after = datetime.now()
        delta2500 = after - before
        _logger.runbot(
            'Static Templates Inheritance: 2500 templates treated in %s seconds'
            % delta2500.total_seconds())

        whole_tree = etree.fromstring(contents)
        self.assertEqual(len(whole_tree),
                         nMod * nFilePerMod * nTemplatePerFile)

        # With 25000 templates next
        nMod, nFilePerMod, nTemplatePerFile = 50, 5, 100
        self._sick_script(nMod, nFilePerMod, nTemplatePerFile)

        before = datetime.now()
        HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        after = datetime.now()
        delta25000 = after - before

        time_ratio = delta25000.total_seconds() / delta2500.total_seconds()
        _logger.runbot(
            'Static Templates Inheritance: 25000 templates treated in %s seconds'
            % delta25000.total_seconds())
        _logger.runbot(
            'Static Templates Inheritance: Computed linearity ratio: %s' %
            time_ratio)
        self.assertLessEqual(time_ratio, 12)
예제 #8
0
    def test_static_inheritance_03(self):
        self.maxDiff = None
        self.template_files = {
            'module_1_file_1':
            b'''
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1">
                        <div>At first I was afraid</div>
                        <div>Kept thinking I could never live without you by my side</div>
                    </form>
                    <form t-name="template_1_2" t-inherit="template_1_1" added="true">
                        <xpath expr="//div[1]" position="after">
                            <div>I was petrified</div>
                        </xpath>
                    </form>
                    <form t-name="template_1_3" t-inherit="template_1_2" added="false" other="here">
                        <xpath expr="//div[2]" position="replace"/>
                    </form>
                </templates>
            '''
        }
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1">
                    <div>At first I was afraid</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
                <form t-name="template_1_2" added="true">
                    <div>At first I was afraid</div>
                    <div>I was petrified</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
                <form t-name="template_1_3" added="false" other="here">
                    <div>At first I was afraid</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #9
0
    def test_static_inherit_extended_template(self):
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b'''
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1">
                        <div>At first I was afraid</div>
                        <div>Kept thinking I could never live without you by my side</div>
                    </form>
                    <form t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="extension">
                        <xpath expr="//div[1]" position="after">
                            <div>I was petrified</div>
                        </xpath>
                    </form>
                    <form t-name="template_1_3" t-inherit="template_1_1" t-inherit-mode="primary">
                        <xpath expr="//div[3]" position="after">
                            <div>But then I spent so many nights thinking how you did me wrong</div>
                        </xpath>
                    </form>
                </templates>
            ''',
        }
        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1">
                    <div>At first I was afraid</div>
                    <div>I was petrified</div>
                    <div>Kept thinking I could never live without you by my side</div>
                </form>
                <form t-name="template_1_3">
                    <div>At first I was afraid</div>
                    <div>I was petrified</div>
                    <div>Kept thinking I could never live without you by my side</div>
                    <div>But then I spent so many nights thinking how you did me wrong</div>
                </form>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #10
0
    def test_inherit_from_dotted_tname_3(self):
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
            ('module_2_file_1', 'module_2', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="module_1.template_1_1.dot" random-attr="gloria">
                        <div>At first I was afraid</div>
                    </form>
                </templates>
                """,
            'module_2_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <t t-name="template_2_1" t-inherit="module_1.template_1_1.dot" t-inherit-mode="primary">
                        <xpath expr="." position="replace">
                            <div overriden-attr="overriden">
                                And I grew strong
                                <p>And I learned how to get along</p>
                            </div>
                        </xpath>
                    </t>
                </templates>
            """
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="module_1.template_1_1.dot" random-attr="gloria">
                    <div>At first I was afraid</div>
                 </form>
                 <div overriden-attr="overriden" t-name="template_2_1">
                    And I grew strong
                    <p>And I learned how to get along</p>
                 </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #11
0
 def session_info(self):
     user = request.env.user
     result = super(IrHttp, self).session_info()
     if self.env.user.has_group('base.group_user'):
         result['notification_type'] = user.notification_type
     assets_discuss_public_hash = HomeStaticTemplateHelpers.get_qweb_templates_checksum(debug=request.session.debug, bundle='mail.assets_discuss_public')
     result['cache_hashes']['assets_discuss_public'] = assets_discuss_public_hash
     guest = self.env.context.get('guest')
     if not request.session.uid and guest:
         user_context = {'lang': guest.lang}
         mods = odoo.conf.server_wide_modules or []
         lang = user_context.get("lang")
         translation_hash = request.env['ir.translation'].sudo().get_web_translations_hash(mods, lang)
         result['cache_hashes']['translations'] = translation_hash
         result.update({
             'name': guest.name,
             'user_context': user_context,
         })
     return result
예제 #12
0
    def test_inherit_primary_replace_debug(self):
        """
        The inheriting template has got both its own defining attrs
        and new ones if one is to replace its defining root node
        """
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1" random-attr="gloria">
                        <div>At first I was afraid</div>
                    </form>
                    <t t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="primary">
                        <xpath expr="." position="replace">
                            <div overriden-attr="overriden">
                                And I grew strong
                                <p>And I learned how to get along</p>
                            </div>
                        </xpath>
                    </t>
                </templates>
                """,
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1" random-attr="gloria">
                    <div>At first I was afraid</div>
                 </form>
                 <div overriden-attr="overriden" t-name="template_1_2">
                    And I grew strong
                    <p>And I learned how to get along</p>
                 </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #13
0
    def test_replace_in_debug_mode3(self):
        """Text outside of a div which will replace a whole template
        becomes outside of the template
        This doesn't mean anything in terms of the business of template inheritance
        But it is in the XPATH specs"""
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1" random-attr="gloria">
                        <div>At first I was afraid</div>
                    </form>
                    <t t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="extension">
                        <xpath expr="." position="replace">
                            <div>
                                And I grew strong
                                <p>And I learned how to get along</p>
                            </div>
                            And so you're back
                        </xpath>
                    </t>
                </templates>
                """,
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <div t-name="template_1_1">
                    And I grew strong
                    <p>And I learned how to get along</p>
                </div>
                And so you're back
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #14
0
    def test_replace_root_node_tag_in_primary(self):
        """
        Root node IS targeted by //NODE_TAG in xpath
        """
        self.maxDiff = None
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1" random-attr="gloria">
                        <div>At first I was afraid</div>
                        <form>Inner Form</form>
                    </form>
                    <form t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="primary">
                        <xpath expr="//form" position="replace">
                            <div>Form replacer</div>
                        </xpath>
                    </form>
                </templates>
                """,
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=True)
        expected = b"""
            <templates>
                <form t-name="template_1_1" random-attr="gloria">
                    <div>At first I was afraid</div>
                    <form>Inner Form</form>
                </form>
                <div t-name="template_1_2">
                    Form replacer
                </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #15
0
    def test_replace_in_nodebug_mode1(self):
        """Comments already in the arch are ignored"""
        self.asset_paths = [
            ('module_1_file_1', 'module_1', 'bundle_1'),
        ]
        self.template_files = {
            'module_1_file_1':
            b"""
                <templates id="template" xml:space="preserve">
                    <form t-name="template_1_1" random-attr="gloria">
                        <div>At first I was afraid</div>
                    </form>
                    <t t-name="template_1_2" t-inherit="template_1_1" t-inherit-mode="extension">
                        <xpath expr="." position="replace">
                            <div>
                                <!-- Random Comment -->
                                And I grew strong
                                <p>And I learned how to get along</p>
                                And so you're back
                            </div>
                        </xpath>
                    </t>
                </templates>
                """,
        }

        contents = HomeStaticTemplateHelpers.get_qweb_templates(
            addons=self._get_module_names(), debug=False)
        expected = b"""
            <templates>
                <div t-name="template_1_1">
                    And I grew strong
                    <p>And I learned how to get along</p>
                    And so you're back
                </div>
            </templates>
        """

        self.assertXMLEqual(contents, expected)
예제 #16
0
    def render_production_backend_view(self, picking_id):
        try:
            picking = self._document_check_access('stock.picking', picking_id)
        except (AccessError, MissingError):
            raise werkzeug.exceptions.NotFound
        session_info = request.env['ir.http'].session_info()
        user_context = dict(request.env.context) if request.session.uid else {}
        mods = conf.server_wide_modules or []
        qweb_checksum = HomeStaticTemplateHelpers.get_qweb_templates_checksum(
            debug=request.session.debug,
            bundle="mrp_subcontracting.assets_qweb")
        lang = user_context.get("lang")
        translation_hash = request.env[
            'ir.translation'].get_web_translations_hash(mods, lang)
        cache_hashes = {
            "qweb": qweb_checksum,
            "translations": translation_hash,
        }
        production_company = picking.company_id
        session_info.update(
            cache_hashes=cache_hashes,
            action_name=
            'mrp_subcontracting.subcontracting_portal_view_production_action',
            picking_id=picking.id,
            user_companies={
                'current_company': production_company.id,
                'allowed_companies': {
                    production_company.id: {
                        'id': production_company.id,
                        'name': production_company.name,
                    },
                },
            })

        return request.render(
            'mrp_subcontracting.subcontracting_portal_embed',
            {'session_info': session_info},
        )
예제 #17
0
파일: ir_http.py 프로젝트: GSLabIt/odoo
    def session_info(self):
        user = request.env.user
        session_uid = request.session.uid
        version_info = odoo.service.common.exp_version()

        if session_uid:
            user_context = dict(self.env['res.users'].context_get())
            if user_context != request.session.context:
                request.session.context = user_context
        else:
            user_context = {}

        IrConfigSudo = self.env['ir.config_parameter'].sudo()
        max_file_upload_size = int(IrConfigSudo.get_param(
            'web.max_file_upload_size',
            default=128 * 1024 * 1024,  # 128MiB
        ))
        mods = odoo.conf.server_wide_modules or []
        session_info = {
            "uid": session_uid,
            "is_system": user._is_system() if session_uid else False,
            "is_admin": user._is_admin() if session_uid else False,
            "user_context": user_context,
            "db": request.db,
            "server_version": version_info.get('server_version'),
            "server_version_info": version_info.get('server_version_info'),
            "support_url": "https://www.odoo.com/buy",
            "name": user.name,
            "username": user.login,
            "partner_display_name": user.partner_id.display_name,
            "company_id": user.company_id.id if session_uid else None,  # YTI TODO: Remove this from the user context
            "partner_id": user.partner_id.id if session_uid and user.partner_id else None,
            "web.base.url": IrConfigSudo.get_param('web.base.url', default=''),
            "active_ids_limit": int(IrConfigSudo.get_param('web.active_ids_limit', default='20000')),
            'profile_session': request.session.profile_session,
            'profile_collectors': request.session.profile_collectors,
            'profile_params': request.session.profile_params,
            "max_file_upload_size": max_file_upload_size,
            "home_action_id": user.action_id.id,
            "cache_hashes": {
                "translations": request.env['ir.translation'].sudo().get_web_translations_hash(
                    mods, request.session.context['lang']
                ) if session_uid else None,
            },
            "currencies": self.sudo().get_currencies(),
        }
        if self.env.user.has_group('base.group_user'):
            # the following is only useful in the context of a webclient bootstrapping
            # but is still included in some other calls (e.g. '/web/session/authenticate')
            # to avoid access errors and unnecessary information, it is only included for users
            # with access to the backend ('internal'-type users)
            if request.db:
                mods = list(request.registry._init_modules) + mods
            qweb_checksum = HomeStaticTemplateHelpers.get_qweb_templates_checksum(debug=request.session.debug, bundle="web.assets_qweb")
            menus = request.env['ir.ui.menu'].load_menus(request.session.debug)
            ordered_menus = {str(k): v for k, v in menus.items()}
            menu_json_utf8 = json.dumps(ordered_menus, default=ustr, sort_keys=True).encode()
            session_info['cache_hashes'].update({
                "load_menus": hashlib.sha512(menu_json_utf8).hexdigest()[:64], # sha512/256
                "qweb": qweb_checksum,
            })
            session_info.update({
                # current_company should be default_company
                "user_companies": {
                    'current_company': user.company_id.id,
                    'allowed_companies': {
                        comp.id: {
                            'id': comp.id,
                            'name': comp.name,
                            'sequence': comp.sequence,
                        } for comp in user.company_ids
                    },
                },
                "show_effect": True,
                "display_switch_company_menu": user.has_group('base.group_multi_company') and len(user.company_ids) > 1,
            })
        return session_info