예제 #1
0
 def get_theme_template_sources():
     """
     Return template sources for the given theme and if request object is None (this would be the case for
     management commands) return template sources for all themes.
     """
     if not get_current_request():
         # if request object is not present, then this method is being called inside a management
         # command and return all theme template sources for compression
         return get_all_theme_template_dirs()
     else:
         # template is being accessed by a view, so return templates sources for current theme
         return get_current_theme_template_dirs()
예제 #2
0
    def test_get_all_theme_template_dirs(self):
        """
        Tests get_all_theme_template_dirs returns correct template dirs for all the themes.
        """
        themes_dir = Path(settings.COMPREHENSIVE_THEME_DIR)

        expected_theme_dirs = [
            themes_dir / "test-theme" / "templates",
            themes_dir / "test-theme" / "templates" / "oscar",
            themes_dir / "test-theme-2" / "templates",
            themes_dir / "test-theme-2" / "templates" / "oscar",
        ]
        actual_theme_dirs = get_all_theme_template_dirs()
        self.assertItemsEqual(expected_theme_dirs, actual_theme_dirs)
예제 #3
0
    def test_get_all_theme_template_dirs(self):
        """
        Tests get_all_theme_template_dirs returns correct template dirs for all the themes.
        """
        themes_dirs = settings.COMPREHENSIVE_THEME_DIRS

        expected_theme_dirs = [
            themes_dirs[0] / "test-theme" / "templates",
            themes_dirs[0] / "test-theme" / "templates" / "oscar",
            themes_dirs[0] / "test-theme-2" / "templates",
            themes_dirs[0] / "test-theme-2" / "templates" / "oscar",
            themes_dirs[1] / "test-theme-3" / "templates",
            themes_dirs[1] / "test-theme-3" / "templates" / "oscar",
        ]
        actual_theme_dirs = get_all_theme_template_dirs()
        self.assertItemsEqual(expected_theme_dirs, actual_theme_dirs)
예제 #4
0
    def test_get_all_theme_template_dirs(self):
        """
        Tests get_all_theme_template_dirs returns correct template dirs for all the themes.
        """
        themes_dirs = settings.COMPREHENSIVE_THEME_DIRS

        expected_theme_dirs = [
            themes_dirs[0] / "test-theme" / "templates",
            themes_dirs[0] / "test-theme" / "templates" / "oscar",
            themes_dirs[0] / "test-theme-2" / "templates",
            themes_dirs[0] / "test-theme-2" / "templates" / "oscar",
            themes_dirs[1] / "test-theme-3" / "templates",
            themes_dirs[1] / "test-theme-3" / "templates" / "oscar",
        ]
        actual_theme_dirs = get_all_theme_template_dirs()
        six.assertCountEqual(self, expected_theme_dirs, actual_theme_dirs)
예제 #5
0
    def get_dirs(self):
        dirs = super(ThemeTemplateLoader, self).get_dirs()
        theme_dirs = []

        if get_current_request():
            # If the template is being loaded in a request, prepend the current theme's template directories
            # so the theme's templates take precedence.
            theme = get_current_theme()

            if theme:
                theme_dirs = theme.template_dirs
        else:
            # If we are outside of a request, we are most likely running the compress management command, in which
            # case we should load all directories for all themes.
            theme_dirs = get_all_theme_template_dirs()

        return theme_dirs + dirs