Пример #1
0
 def test_strip_site_theme_templates_path_theme_disabled(self):
     """
     Tests site theme templates path returned unchanged if no theme is applied.
     """
     template_path = strip_site_theme_templates_path(
         '/red-theme/cms/templates/login.html')
     self.assertEqual(template_path, '/red-theme/cms/templates/login.html')
Пример #2
0
 def _get_toplevel_template(self, uri):
     """
     Lookup a default/toplevel template, ignoring current theme.
     """
     # Strip off the prefix path to theme and look in default template dirs.
     return super(DynamicTemplateLookup,
                  self).get_template(strip_site_theme_templates_path(uri))
Пример #3
0
    def get_template(self, uri):
        """
        Overridden method for locating a template in either the database or the site theme.

        If not found, template lookup will be done in comprehensive theme for current site
        by prefixing path to theme.
        e.g if uri is `main.html` then new uri would be something like this `/red-theme/lms/static/main.html`

        If still unable to find a template, it will fallback to the default template directories after stripping off
        the prefix path to theme.
        """
        # try to get template for the given file from microsite
        template = themed_template(uri)

        # if microsite template is not present or request is not in microsite then
        # let mako find and serve a template
        if not template:
            try:
                # Try to find themed template, i.e. see if current theme overrides the template
                template = super(DynamicTemplateLookup, self).get_template(
                    get_template_path_with_theme(uri))
            except TopLevelLookupException:
                # strip off the prefix path to theme and look in default template dirs
                template = super(DynamicTemplateLookup, self).get_template(
                    strip_site_theme_templates_path(uri))

        return template
Пример #4
0
 def test_strip_site_theme_templates_path_theme_enabled(self):
     """
     Tests site theme templates path is stripped from the given template path.
     """
     template_path = strip_site_theme_templates_path(
         '/red-theme/cms/templates/login.html')
     self.assertEqual(template_path, 'login.html')
Пример #5
0
 def test_strip_site_theme_templates_path_theme_enabled(self):
     """
     Tests site theme templates path is stripped from the given template path.
     """
     template_path = strip_site_theme_templates_path(
         '/red-theme/lms/templates/header.html')
     assert template_path == 'header.html'
Пример #6
0
 def test_strip_site_theme_templates_path_theme_disabled(self):
     """
     Tests site theme templates path returned unchanged if no theme is applied.
     """
     template_path = strip_site_theme_templates_path(
         '/red-theme/lms/templates/header.html')
     assert template_path == '/red-theme/lms/templates/header.html'
Пример #7
0
    def get_template(self, uri):
        """
        Overridden method for locating a template in either the database or the site theme.

        If not found, template lookup will be done in comprehensive theme for current site
        by prefixing path to theme.
        e.g if uri is `main.html` then new uri would be something like this `/red-theme/lms/static/main.html`

        If still unable to find a template, it will fallback to the default template directories after stripping off
        the prefix path to theme.
        """
        # try to get template for the given file from microsite
        template = themed_template(uri)

        # if microsite template is not present or request is not in microsite then
        # let mako find and serve a template
        if not template:
            try:
                # Try to find themed template, i.e. see if current theme overrides the template
                template = super(DynamicTemplateLookup, self).get_template(get_template_path_with_theme(uri))
            except TopLevelLookupException:
                # strip off the prefix path to theme and look in default template dirs
                template = super(DynamicTemplateLookup, self).get_template(strip_site_theme_templates_path(uri))

        return template
Пример #8
0
 def _get_toplevel_template(self, uri):
     """
     Lookup a default/toplevel template, ignoring current theme.
     """
     # Strip off the prefix path to theme and look in default template dirs.
     return super(DynamicTemplateLookup,
                  self).get_template(strip_site_theme_templates_path(uri))  # lint-amnesty, pylint: disable=super-with-arguments
Пример #9
0
    def adjust_uri(self, uri, calling_uri):
        """
        This method is called by mako when including a template in another template or when inheriting an existing mako
        template. The method adjusts the `uri` to make it relative to the calling template's location.

        This method is overridden to detect when a template from a theme tries to override the same template from a
        standard location, for example when the dashboard.html template is overridden in the theme while at the same
        time inheriting from the standard LMS dashboard.html template.

        When this self-inheritance is detected, the uri is wrapped in the TopLevelTemplateURI marker class to ensure
        that template lookup skips the current theme and looks up the built-in template in standard locations.
        """
        # Make requested uri relative to the calling uri.
        relative_uri = super(DynamicTemplateLookup, self).adjust_uri(uri, calling_uri)
        # Is the calling template (calling_uri) which is including or inheriting current template (uri)
        # located inside a theme?
        if calling_uri != strip_site_theme_templates_path(calling_uri):
            # Is the calling template trying to include/inherit itself?
            if calling_uri == get_template_path_with_theme(relative_uri):
                return TopLevelTemplateURI(relative_uri)
        return relative_uri
Пример #10
0
    def adjust_uri(self, uri, relativeto):
        """
        This method is called by mako when including a template in another template or when inheriting an existing mako
        template. The method adjusts the `uri` to make it relative to the calling template's location.

        This method is overridden to detect when a template from a theme tries to override the same template from a
        standard location, for example when the dashboard.html template is overridden in the theme while at the same
        time inheriting from the standard LMS dashboard.html template.

        When this self-inheritance is detected, the uri is wrapped in the TopLevelTemplateURI marker class to ensure
        that template lookup skips the current theme and looks up the built-in template in standard locations.
        """
        # Make requested uri relative to the calling uri.
        relative_uri = super(DynamicTemplateLookup, self).adjust_uri(uri, relativeto)
        # Is the calling template (relativeto) which is including or inheriting current template (uri)
        # located inside a theme?
        if relativeto != strip_site_theme_templates_path(relativeto):
            # Is the calling template trying to include/inherit itself?
            if relativeto == get_template_path_with_theme(relative_uri):
                return TopLevelTemplateURI(relative_uri)
        return relative_uri
Пример #11
0
 def test_strip_site_theme_templates_path_theme_disabled(self):
     """
     Tests site theme templates path returned unchanged if no theme is applied.
     """
     template_path = strip_site_theme_templates_path('/red-theme/cms/templates/login.html')
     self.assertEqual(template_path, '/red-theme/cms/templates/login.html')
Пример #12
0
 def test_strip_site_theme_templates_path_theme_enabled(self):
     """
     Tests site theme templates path is stripped from the given template path.
     """
     template_path = strip_site_theme_templates_path('/red-theme/cms/templates/login.html')
     self.assertEqual(template_path, 'login.html')
Пример #13
0
 def _get_toplevel_template(self, uri):
     """
     Lookup a default/toplevel template, ignoring current theme.
     """
     # Strip off the prefix path to theme and look in default template dirs.
     return super(DynamicTemplateLookup, self).get_template(strip_site_theme_templates_path(uri))