X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/ac6ebd8b38a46afb0b249574be71a276f95b6efa..34a9cd2a670e84771d1d54e6fd6af87bcb1c279c:/philo/templatetags/containers.py diff --git a/philo/templatetags/containers.py b/philo/templatetags/containers.py index 1e2ff80..be94a3d 100644 --- a/philo/templatetags/containers.py +++ b/philo/templatetags/containers.py @@ -1,3 +1,8 @@ +""" +The container template tags are automatically included as builtins if :mod:`philo` is an installed app. + +""" + from django import template from django.conf import settings from django.contrib.contenttypes.models import ContentType @@ -43,26 +48,19 @@ class ContainerNode(template.Node): # Otherwise it's a contentlet. try: contentlet = page.contentlets.get(name__exact=self.name) - if '{%' in contentlet.content or '{{' in contentlet.content: - try: - content = template.Template(contentlet.content, name=contentlet.name).render(context) - except template.TemplateSyntaxError, error: - if settings.DEBUG: - content = ('[Error parsing contentlet \'%s\': %s]' % (self.name, error)) - else: - content = settings.TEMPLATE_STRING_IF_INVALID - else: - content = contentlet.content + content = contentlet.content except ObjectDoesNotExist: - content = settings.TEMPLATE_STRING_IF_INVALID - content = mark_safe(content) + content = '' return content -def do_container(parser, token): +@register.tag +def container(parser, token): """ + If a template using this tag is used to render a :class:`.Page`, that :class:`.Page` will have associated content which can be set in the admin interface. If a content type is referenced, then a :class:`.ContentReference` object will be created; otherwise, a :class:`.Contentlet` object will be created. + Usage:: - + {% container [[references .] as ] %} """ @@ -79,7 +77,7 @@ def do_container(parser, token): if option_token == 'references': try: app_label, model = remaining_tokens.pop(0).strip('"').split('.') - references = ContentType.objects.get(app_label=app_label, model=model) + references = ContentType.objects.get_by_natural_key(app_label, model) except IndexError: raise template.TemplateSyntaxError('"%s" template tag option "references" requires an argument specifying a content type' % tag) except ValueError: @@ -97,6 +95,3 @@ def do_container(parser, token): else: # error raise template.TemplateSyntaxError('"%s" template tag provided without arguments (at least one required)' % tag) - - -register.tag('container', do_container)