コード例 #1
0
ファイル: paths.py プロジェクト: yellowsignz/edx-platform
    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
コード例 #2
0
ファイル: paths.py プロジェクト: Lektorium-LLC/edx-platform
    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
コード例 #3
0
ファイル: paths.py プロジェクト: AlexxNica/edx-platform
    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
コード例 #4
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.
        """
        if isinstance(uri, TopLevelTemplateURI):
            template = self._get_toplevel_template(uri)
        else:
            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:
                template = self._get_toplevel_template(uri)

        return template
コード例 #5
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
コード例 #6
0
 def test_get_template_path_with_theme_disabled(self):
     """
     Tests default template paths are returned when theme is non theme is enabled.
     """
     template_path = get_template_path_with_theme('login.html')
     self.assertEqual(template_path, 'login.html')
コード例 #7
0
 def test_get_template_path_with_theme_for_missing_template(self):
     """
     Tests default template paths are returned if template is not found in the theme.
     """
     template_path = get_template_path_with_theme('certificates.html')
     self.assertEqual(template_path, 'certificates.html')
コード例 #8
0
 def test_get_template_path_with_theme_enabled(self):
     """
     Tests template paths are returned from enabled theme.
     """
     template_path = get_template_path_with_theme('login.html')
     self.assertEqual(template_path, 'red-theme/cms/templates/login.html')
コード例 #9
0
ファイル: test_helpers.py プロジェクト: gopinath81/vmss
 def test_get_template_path_with_theme_disabled(self):
     """
     Tests default template paths are returned when theme is non theme is enabled.
     """
     template_path = get_template_path_with_theme('login.html')
     self.assertEqual(template_path, 'login.html')
コード例 #10
0
ファイル: test_helpers.py プロジェクト: gopinath81/vmss
 def test_get_template_path_with_theme_for_missing_template(self):
     """
     Tests default template paths are returned if template is not found in the theme.
     """
     template_path = get_template_path_with_theme('certificates.html')
     self.assertEqual(template_path, 'certificates.html')
コード例 #11
0
ファイル: test_helpers.py プロジェクト: gopinath81/vmss
 def test_get_template_path_with_theme_enabled(self):
     """
     Tests template paths are returned from enabled theme.
     """
     template_path = get_template_path_with_theme('login.html')
     self.assertEqual(template_path, 'red-theme/cms/templates/login.html')
コード例 #12
0
ファイル: test_helpers.py プロジェクト: sshyran/edx-platform
 def test_get_template_path_with_theme_disabled(self):
     """
     Tests default template paths are returned when theme is non theme is enabled.
     """
     template_path = get_template_path_with_theme('header.html')
     assert template_path == 'header.html'
コード例 #13
0
ファイル: test_helpers.py プロジェクト: sshyran/edx-platform
 def test_get_template_path_with_theme_for_missing_template(self):
     """
     Tests default template paths are returned if template is not found in the theme.
     """
     template_path = get_template_path_with_theme('course.html')
     assert template_path == 'course.html'
コード例 #14
0
ファイル: test_helpers.py プロジェクト: sshyran/edx-platform
 def test_get_template_path_with_theme_enabled(self):
     """
     Tests template paths are returned from enabled theme.
     """
     template_path = get_template_path_with_theme('header.html')
     assert template_path == 'red-theme/lms/templates/header.html'