def test_display_context(self): # With DEBUG on, display_context() inserts the values of context vars t = env.from_string('START{{ display_context() }}END') c = Context({'testkey': 'testvalue'}) s = t.render(c) ok_('START<dl' in s) ok_('</dl>END' in s) ok_("<dt>testkey</dt><dd>'testvalue'</dd>" in s)
def dump_messages(messages): t = env.from_string(''' {% if messages %} {% for message in messages %} <div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">{{ message }}</div> {% endfor %} {% endif %} ''') return Markup(t.render(dict(messages=messages)))
def dump_errors(errors): t = env.from_string(''' {% if errors %} {% for field_name, field_errors in errors.items() %} {% for err in field_errors %} <div class="alert alert-error"> {{ err }} </div> {%endfor%} {% endfor %} {% endif %} ''') return Markup(t.render(dict(errors=errors)))
def render(self, locale=None): current_langauge = False if locale: current_langauge = translation.get_language() translation.activate(locale) data = dict([(name, Markup(item["value"])) for name, item in json.loads(self.data).items()]) rendered_snippet = '<div data-snippet-id="{0}">{1}</div>'.format( self.id, env.from_string(self.template.code).render(data) ) if current_langauge: translation.activate(current_langauge) return Markup(rendered_snippet)
def render(s, context={}): """Taken from jingo.tests.utils, previously jingo.tests.test_helpers.""" t = env.from_string(s) return t.render(context)
def base_template_view(request): template = env.from_string(""" {% extends 'facebook/base.html' %} {% block content %}test{% endblock %} """) return HttpResponse(template.render(RequestContext(request)))
def test_display_context_production(self): # With DEBUG off, display_context() is empty t = env.from_string('START{{ display_context() }}END') c = Context({'testkey': 'testvalue'}) s = t.render(c) eq_('STARTEND', s)
def render(s, context={}): return env.from_string(s).render(context)
def render(s, context={}): t = env.from_string(s) return t.render(context)