class Loader

from dj_angles.template_loader import Loader


  

Ancestors (MRO)

  1. builtins.object
  2. django.template.loaders.base.Loader
  3. django.template.loaders.filesystem.Loader
  4. django.template.loaders.app_directories.Loader
  5. dj_angles.template_loader.Loader
AttributeTypeDefined in
def __init__(self, engine, dirs=None)
django.template.loaders.filesystem.Loader
django.template.loaders.filesystem.Loader
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, engine, dirs=None):
        super().__init__(engine)
        self.dirs = dirs
django.template.loaders.base.Loader
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, engine):
        self.engine = engine
def get_contents(self)
dj_angles.template_loader.Loader
dj_angles.template_loader.Loader
Gets the converted template contents.
    def get_contents(self, origin) -> str:
        """Gets the converted template contents."""

        template_string = self._get_template_string(origin.name)
        converted_template_string = replace_django_template_tags(template_string)

        return converted_template_string
django.template.loaders.filesystem.Loader
    def get_contents(self, origin):
        try:
            with open(origin.name, encoding=self.engine.file_charset) as fp:
                return fp.read()
        except FileNotFoundError:
            raise TemplateDoesNotExist(origin)
def get_dirs(self)
dj_angles.template_loader.Loader
dj_angles.template_loader.Loader
Gets the template directories. This works like the file loader with `APP_DIRS = True`.

From https://github.com/wrabit/django-cotton/blob/ab1a98052de48266c62ff226ab0ec85b89d038b6/django_cotton/cotton_loader.py#L59.
    def get_dirs(self):
        """Gets the template directories. This works like the file loader with `APP_DIRS = True`.

        From https://github.com/wrabit/django-cotton/blob/ab1a98052de48266c62ff226ab0ec85b89d038b6/django_cotton/cotton_loader.py#L59.
        """

        dirs = self.engine.dirs

        for app_config in apps.get_app_configs():
            template_dir = os.path.join(app_config.path, "templates")

            if os.path.isdir(template_dir):
                dirs.append(template_dir)

        return dirs
django.template.loaders.app_directories.Loader
    def get_dirs(self):
        return get_app_template_dirs("templates")
django.template.loaders.filesystem.Loader
    def get_dirs(self):
        return self.dirs if self.dirs is not None else self.engine.dirs
def get_template(self, template_name, skip=None)
django.template.loaders.base.Loader
Call self.get_template_sources() and return a Template object for
the first template matching template_name. If skip is provided, ignore
template origins in skip. This is used to avoid recursion during
template extending.
    def get_template(self, template_name, skip=None):
        """
        Call self.get_template_sources() and return a Template object for
        the first template matching template_name. If skip is provided, ignore
        template origins in skip. This is used to avoid recursion during
        template extending.
        """
        tried = []

        for origin in self.get_template_sources(template_name):
            if skip is not None and origin in skip:
                tried.append((origin, "Skipped to avoid recursion"))
                continue

            try:
                contents = self.get_contents(origin)
            except TemplateDoesNotExist:
                tried.append((origin, "Source does not exist"))
                continue
            else:
                return Template(
                    contents,
                    origin,
                    origin.template_name,
                    self.engine,
                )

        raise TemplateDoesNotExist(template_name, tried=tried)
def get_template_sources(self, template_name)
django.template.loaders.filesystem.Loader
django.template.loaders.filesystem.Loader
Return an Origin object pointing to an absolute path in each directory
in template_dirs. For security reasons, if a path doesn't lie inside
one of the template_dirs it is excluded from the result set.
    def get_template_sources(self, template_name):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        for template_dir in self.get_dirs():
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            )
django.template.loaders.base.Loader
An iterator that yields possible matching template paths for a
template name.
    def get_template_sources(self, template_name):
        """
        An iterator that yields possible matching template paths for a
        template name.
        """
        raise NotImplementedError(
            "subclasses of Loader must provide a get_template_sources() method"
        )
def reset(self)
django.template.loaders.base.Loader
Reset any state maintained by the loader instance (e.g. cached
templates or cached loader modules).
    def reset(self):
        """
        Reset any state maintained by the loader instance (e.g. cached
        templates or cached loader modules).
        """
        pass