예제 #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)