Exemple #1
0
    def _get_themed_template_names(self, name):
        """
        Get theme-prefixed paths for the given template name.

        For instance, if the template_dir or identifier of the current theme is `mystery` and we're looking up
        `shuup/front/bar.jinja`, we'll look at `mystery/shuup/front/bar.jinja`, finally at `shuup/front/bar.jinja`.

        Mystery theme also can define default template dir let's say `pony`. In this scenario we're looking up
        `shuup/front/bar.jinja` from `mystery/shuup/front/bar.jinja` then at `pony/shuup/front/bar.jinja` and
        finally at the default `shuup/front/bar.jinja`.

        :param name: Template name
        :type name: str
        :return: A template name or a list thereof
        :rtype: str|list[str]
        """
        if name.startswith("shuup/admin"):  # Ignore the admin.
            return name

        # we strongly depend on the XthemMiddleware as it should set the current theme
        # for this thread based on the request it processes
        theme = get_middleware_current_theme()
        if not theme:
            return name
        theme_template = "%s/%s" % (
            (theme.template_dir or theme.identifier), name)
        default_template = (("%s/%s" % (theme.default_template_dir, name))
                            if theme.default_template_dir else None)
        return [theme_template, default_template, name
                ] if default_template else [theme_template, name]
Exemple #2
0
    def _get_themed_template_names(self, name):
        """
        Get theme-prefixed paths for the given template name.

        For instance, if the template_dir or identifier of the current theme is `mystery` and we're looking up
        `shuup/front/bar.jinja`, we'll look at `mystery/shuup/front/bar.jinja`, finally at `shuup/front/bar.jinja`.

        Mystery theme also can define default template dir let's say `pony`. In this scenario we're looking up
        `shuup/front/bar.jinja` from `mystery/shuup/front/bar.jinja` then at `pony/shuup/front/bar.jinja` and
        finally at the default `shuup/front/bar.jinja`.

        :param name: Template name
        :type name: str
        :return: A template name or a list thereof
        :rtype: str|list[str]
        """
        if name.startswith("shuup/admin"):  # Ignore the admin.
            return name

        # we strongly depend on the XthemMiddleware as it should set the current theme
        # for this thread based on the request it processes
        theme = get_middleware_current_theme()
        if not theme:
            return name
        theme_template = "%s/%s" % ((theme.template_dir or theme.identifier), name)
        default_template = (("%s/%s" % (theme.default_template_dir, name)) if theme.default_template_dir else None)
        return [theme_template, default_template, name] if default_template else [theme_template, name]
Exemple #3
0
    def __getitem__(self, item):
        """
        Look for additional helper callables in the active theme.

        Callables marked with the Django standard `alters_data` attribute will not be honored.

        :param item: Template helper name
        :type item: str
        :return: Template helper, maybe
        :rtype: object|None
        """
        theme = get_middleware_current_theme()
        if theme:
            helper = getattr(theme, item, None)
            if helper and callable(helper) and not getattr(helper, "alters_data", False):
                return helper
        raise KeyError("No such template helper: %s" % item)
Exemple #4
0
    def __getitem__(self, item):
        """
        Look for additional helper callables in the active theme.

        Callables marked with the Django standard `alters_data` attribute will not be honored.

        :param item: Template helper name
        :type item: str
        :return: Template helper, maybe
        :rtype: object|None
        """
        theme = get_middleware_current_theme()
        if theme:
            helper = getattr(theme, item, None)
            if helper and callable(helper) and not getattr(helper, "alters_data", False):
                return helper
        raise KeyError("No such template helper: %s" % item)