django.template.engines.all - python examples

Here are the examples of the python api django.template.engines.all taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

3 View Complete Implementation : test_utils.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(TEMPLATES=[{'BACKEND': 'raise.import.error'}])
    def test_backend_import_error(self):
        """
        Failing to import a backend keeps raising the original import error
        (#24265).
        """
        with self.astertRaisesMessage(ImportError, "No module named 'raise"):
            engines.all()
        with self.astertRaisesMessage(ImportError, "No module named 'raise"):
            engines.all()

3 View Complete Implementation : test_utils.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(TEMPLATES=[{
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # Incorrect: APP_DIRS and loaders are mutually incompatible.
        'APP_DIRS': True,
        'OPTIONS': {'loaders': []},
    }])
    def test_backend_improperly_configured(self):
        """
        Failing to initialize a backend keeps raising the original exception
        (#24265).
        """
        msg = 'app_dirs must not be set when loaders is defined.'
        with self.astertRaisesMessage(ImproperlyConfigured, msg):
            engines.all()
        with self.astertRaisesMessage(ImproperlyConfigured, msg):
            engines.all()

3 View Complete Implementation : test_utils.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(TEMPLATES=[{
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
    }, {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
    }])
    def test_backend_names_must_be_unique(self):
        msg = (
            "Template engine aliases aren't unique, duplicates: django. Set "
            "a unique NAME for each engine in settings.TEMPLATES."
        )
        with self.astertRaisesMessage(ImproperlyConfigured, msg):
            engines.all()

0 View Complete Implementation : engine.py
Copyright MIT License
Author : bpgc-cte
    @staticmethod
    @lru_cache.lru_cache()
    def get_default():
        """
        When only one DjangoTemplates backend is configured, returns it.

        Raises ImproperlyConfigured otherwise.

        This is required for preserving historical APIs that rely on a
        globally available, implicitly configured engine such as:

        >>> from django.template import Context, Template
        >>> template = Template("Hello {{ name }}!")
        >>> context = Context({'name': "world"})
        >>> template.render(context)
        'Hello world!'
        """
        # Since Engine is imported in django.template and since
        # DjangoTemplates is a wrapper around this Engine clast,
        # local imports are required to avoid import loops.
        from django.template import engines
        from django.template.backends.django import DjangoTemplates
        django_engines = [engine for engine in engines.all()
                          if isinstance(engine, DjangoTemplates)]
        if len(django_engines) == 1:
            # Unwrap the Engine instance inside DjangoTemplates
            return django_engines[0].engine
        elif len(django_engines) == 0:
            raise ImproperlyConfigured(
                "No DjangoTemplates backend is configured.")
        else:
            raise ImproperlyConfigured(
                "Several DjangoTemplates backends are configured. "
                "You must select one explicitly.")

0 View Complete Implementation : filters.py
Copyright MIT License
Author : manikos
def progressive(image_field, alt_text=''):
    """
    Used as a Jinja2 filter, this function returns a safe HTML chunk.

    Usage (in the HTML template):

        {{ obj.image|progressive }}

    :param django.db.models.fields.files.ImageFieldFile image_field: image
    :param str alt_text: str
    :return: a safe HTML template ready to be rendered
    """
    if not isinstance(image_field, ImageFieldFile):
        raise ValueError('"image_field" argument must be an ImageField.')

    for engine in engines.all():
        if isinstance(engine, BaseEngine) and hasattr(engine, 'env'):
            env = engine.env
            if isinstance(env, Environment):
                context = render_progressive_field(image_field, alt_text)
                template = env.get_template(
                    'progressiveimagefield/render_field.html'
                )
                rendered = template.render(**context)
                return Markup(rendered)
    return ''

0 View Complete Implementation : apps.py
Copyright MIT License
Author : matthiask
@checks.register()
def check_context_processors(app_configs, **kwargs):
    errors = []

    if VERSION < (2, 2):
        # The admin.E404 check has been introduced in the Django 2.2 cycle.
        return errors

    for engine in engines.all():
        if isinstance(engine, DjangoTemplates):
            django_templates_instance = engine.engine
            break
    else:
        django_templates_instance = None

    if django_templates_instance:
        if (
            "django.contrib.messages.context_processors.messages"
            not in django_templates_instance.context_processors
            and "admin.E404" not in settings.SILENCED_SYSTEM_CHECKS
        ):
            errors.append(
                checks.Error(
                    "If using 'user_messages.context_processors.messages'"
                    " instead of the official messages context processor"
                    " you have to add 'admin.E404' to SILENCED_SYSTEM_CHECKS.",
                    id="user_messages.E001",
                )
            )

    return errors

0 View Complete Implementation : engine.py
Copyright MIT License
Author : rizwansoaib
    @staticmethod
    @functools.lru_cache()
    def get_default():
        """
        Return the first DjangoTemplates backend that's configured, or raise
        ImproperlyConfigured if none are configured.

        This is required for preserving historical APIs that rely on a
        globally available, implicitly configured engine such as:

        >>> from django.template import Context, Template
        >>> template = Template("Hello {{ name }}!")
        >>> context = Context({'name': "world"})
        >>> template.render(context)
        'Hello world!'
        """
        # Since Engine is imported in django.template and since
        # DjangoTemplates is a wrapper around this Engine clast,
        # local imports are required to avoid import loops.
        from django.template import engines
        from django.template.backends.django import DjangoTemplates
        for engine in engines.all():
            if isinstance(engine, DjangoTemplates):
                return engine.engine
        raise ImproperlyConfigured('No DjangoTemplates backend is configured.')

0 View Complete Implementation : checks.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : Ryuchen
def check_dependencies(**kwargs):
    """
    Check that the admin's dependencies are correctly installed.
    """
    if not apps.is_installed('vueSuit.vueAdmin'):
        return []
    errors = []
    app_dependencies = (
        ('django.contrib.contenttypes', 401),
        ('django.contrib.auth', 405),
        ('django.contrib.messages', 406),
    )
    for app_name, error_code in app_dependencies:
        if not apps.is_installed(app_name):
            errors.append(checks.Error(
                "'%s' must be in INSTALLED_APPS in order to use the admin "
                "application." % app_name,
                id='admin.E%d' % error_code,
            ))
    for engine in engines.all():
        if isinstance(engine, DjangoTemplates):
            django_templates_instance = engine.engine
            break
    else:
        django_templates_instance = None
    if not django_templates_instance:
        errors.append(checks.Error(
            "A 'django.template.backends.django.DjangoTemplates' instance "
            "must be configured in TEMPLATES in order to use the admin "
            "application.",
            id='admin.E403',
        ))
    else:
        if ('django.contrib.auth.context_processors.auth'
                not in django_templates_instance.context_processors and
                _contains_subclast('django.contrib.auth.backends.ModelBackend', settings.AUTHENTICATION_BACKENDS)):
            errors.append(checks.Error(
                "'django.contrib.auth.context_processors.auth' must be "
                "enabled in DjangoTemplates (TEMPLATES) if using the default "
                "auth backend in order to use the admin application.",
                id='admin.E402',
            ))
        if ('django.contrib.messages.context_processors.messages'
                not in django_templates_instance.context_processors):
            errors.append(checks.Error(
                "'django.contrib.messages.context_processors.messages' must "
                "be enabled in DjangoTemplates (TEMPLATES) in order to use "
                "the admin application.",
                id='admin.E404',
            ))

    if not _contains_subclast('django.contrib.auth.middleware.AuthenticationMiddleware', settings.MIDDLEWARE):
        errors.append(checks.Error(
            "'django.contrib.auth.middleware.AuthenticationMiddleware' must "
            "be in MIDDLEWARE in order to use the admin application.",
            id='admin.E408',
        ))
    if not _contains_subclast('django.contrib.messages.middleware.MessageMiddleware', settings.MIDDLEWARE):
        errors.append(checks.Error(
            "'django.contrib.messages.middleware.MessageMiddleware' must "
            "be in MIDDLEWARE in order to use the admin application.",
            id='admin.E409',
        ))
    if not _contains_subclast('django.contrib.sessions.middleware.SessionMiddleware', settings.MIDDLEWARE):
        errors.append(checks.Error(
            "'django.contrib.sessions.middleware.SessionMiddleware' must "
            "be in MIDDLEWARE in order to use the admin application.",
            id='admin.E410',
        ))
    return errors