Пример #1
0
    def merge_into(self, environment=None):
        """Push this bundle onto the environment, returning a new env."""

        if environment is None:
            environment = get_env()

        for attr in ['globals', 'filters', 'tests']:
            getattr(environment, attr).update(getattr(self, attr))

        return environment
Пример #2
0
def render_to_string(filename, context=None, environment=None):
    """Renders a given template name to a string."""

    if context is None:
        context = {}

    if environment is None:
        environment = get_env()

    return environment.get_template(filename).render(context_to_dict(context))
Пример #3
0
 def merge_into(self, environment=None):
     """Push this bundle onto the environment, returning a new env."""
     
     if environment is None:
         environment = get_env()
     
     for attr in ['globals', 'filters', 'tests']:
         getattr(environment, attr).update(getattr(self, attr))
     
     return environment
Пример #4
0
def load(app_label, bundle_name, environment=None, reload=False):
    """Load a specified bundle into an/the environment."""

    if environment is None:
        environment = get_env()

    bundle = get_bundle(app_label, bundle_name)
    if (bundle not in environment.loaded_bundles) or reload:
        bundle.merge_into(environment)
        environment.loaded_bundles.add(bundle)
    return bundle
Пример #5
0
def load(app_label, bundle_name, environment=None, reload=False):
    """Load a specified bundle into an/the environment."""
    
    if environment is None:
        environment = get_env()
    
    bundle = get_bundle(app_label, bundle_name)
    if (bundle not in environment.loaded_bundles) or reload:
        bundle.merge_into(environment)
        environment.loaded_bundles.add(bundle)
    return bundle
Пример #6
0
def render_to_string(filename, context=None, environment=None):
    """Renders a given template name to a string."""
    
    if context is None:
        context = {}
    
    if environment is None:
        environment = get_env()
    
    return environment.get_template(filename).render(
        context_to_dict(context))
Пример #7
0
# -*- coding: utf-8 -*-

from django.http import HttpResponse

import djanjinja

local_env = djanjinja.get_env().copy()
local_env.load('djanjinja', 'cache')


def global_(request):
    """Renders a template which uses the global cache object."""

    template = local_env.get_template('cache_global.txt')
    content = template.render().strip()
    return HttpResponse(content=content)
Пример #8
0
# -*- coding: utf-8 -*-

from django.http import HttpResponse

import djanjinja


local_env = djanjinja.get_env().copy()
local_env.load('djanjinja', 'cache')


def global_(request):
    """Renders a template which uses the global cache object."""
    
    template = local_env.get_template('cache_global.txt')
    content = template.render().strip()
    return HttpResponse(content=content)