Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
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)))
Esempio n. 4
0
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)
Esempio n. 6
0
def render(s, context={}):
    """Taken from jingo.tests.utils, previously jingo.tests.test_helpers."""
    t = env.from_string(s)
    return t.render(context)
Esempio n. 7
0
def base_template_view(request):
    template = env.from_string("""
        {% extends 'facebook/base.html' %}
        {% block content %}test{% endblock %}
    """)
    return HttpResponse(template.render(RequestContext(request)))
Esempio n. 8
0
 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)
Esempio n. 9
0
def render(s, context={}):
    """Taken from jingo.tests.utils, previously jingo.tests.test_helpers."""
    t = env.from_string(s)
    return t.render(context)
Esempio n. 10
0
def render(s, context={}):
    return env.from_string(s).render(context)
Esempio n. 11
0
 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)
Esempio n. 12
0
def render(s, context={}):
    t = env.from_string(s)
    return t.render(context)
Esempio n. 13
0
def render(s, context={}):
    return env.from_string(s).render(context)
Esempio n. 14
0
File: utils.py Progetto: chiu/jingo
def render(s, context={}):
    t = env.from_string(s)
    return t.render(context)
Esempio n. 15
0
def base_template_view(request):
    template = env.from_string("""
        {% extends 'facebook/base.html' %}
        {% block content %}test{% endblock %}
    """)
    return HttpResponse(template.render(RequestContext(request)))