call them helpers; templatetags collides with django

This commit is contained in:
Jeff Balogh 2009-12-04 14:58:00 -08:00
Родитель a95fa80391
Коммит 7cb6b678cc
3 изменённых файлов: 8 добавлений и 7 удалений

Просмотреть файл

@ -55,5 +55,5 @@ These filters are injected into all templates automatically. Template filters
are what Jinja uses instead of "helpers" in other systems. They're just
functions that get called from templates using the ``|`` (pipe) syntax.
.. automodule:: jingo.templatetags
.. automodule:: jingo.helpers
:members:

Просмотреть файл

@ -38,10 +38,11 @@ def render(request, template, context=None, **kwargs):
return http.HttpResponse(rendered, **kwargs)
def load_template_tags():
def load_helpers():
"""Try to import ``helpers.py`` from each app in INSTALLED_APPS."""
for app in settings.INSTALLED_APPS:
try:
__import__('%s.templatetags' % app)
__import__('%s.helpers' % app)
except ImportError:
pass
@ -65,5 +66,5 @@ env = get_env()
register = Register(env)
# Import down here after the env is initialized.
from . import templatetags
load_template_tags()
from . import helpers
load_helpers()

Просмотреть файл

@ -34,7 +34,7 @@ def datetime(t, format=_('%B %d, %Y')):
@register.filter
def selected(a, b, text='selected'):
def ifeq(a, b, text):
"""Return ``text`` if ``a == b``."""
return jinja2.Markup(text if a == b else '')
@ -42,4 +42,4 @@ def selected(a, b, text='selected'):
@register.filter
def class_selected(a, b):
"""Return ``'class="selected"'`` if ``a == b``."""
return selected(a, b, 'class="selected"')
return ifeq(a, b, 'class="selected"')