X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/2b9255e08e751c9653078a087b59f4d5169c34fe..17e82da27c3b2de8a6ab4b2e745122c1b3e541c6:/philo/templatetags/containers.py diff --git a/philo/templatetags/containers.py b/philo/templatetags/containers.py index 3370c78..c9ef2a0 100644 --- a/philo/templatetags/containers.py +++ b/philo/templatetags/containers.py @@ -18,17 +18,9 @@ CONTAINER_CONTEXT_KEY = 'philo_container_context' class ContainerContext(object): - def __init__(self, page): - contentlet_specs, contentreference_specs = page.template.containers - - contentlets = page.contentlets.filter(name__in=contentlet_specs) + def __init__(self, contentlets, references): self.contentlets = dict(((c.name, c) for c in contentlets)) - - q = Q() - for name, ct in contentreference_specs.items(): - q |= Q(name=name, content_type=ct) - references = page.contentreferences.filter(q) - self.references = dict(((c.name, c) for c in references)) + self.references = dict((((c.name, ContentType.objects.get_for_id(c.content_type_id)), c) for c in references)) class ContainerNode(template.Node): @@ -38,26 +30,27 @@ class ContainerNode(template.Node): self.references = references def render(self, context): - content = settings.TEMPLATE_STRING_IF_INVALID - if 'page' in context: - container_content = self.get_container_content(context) - else: - container_content = None + container_content = self.get_container_content(context) if self.as_var: context[self.as_var] = container_content return '' - if not container_content: - return '' - return container_content def get_container_content(self, context): try: container_context = context.render_context[CONTAINER_CONTEXT_KEY] except KeyError: - container_context = ContainerContext(context['page']) + try: + page = context['page'] + except KeyError: + return settings.TEMPLATE_STRING_IF_INVALID + + contentlets = page.contentlets.all() + references = page.contentreferences.all() + + container_context = ContainerContext(contentlets, references) context.render_context[CONTAINER_CONTEXT_KEY] = container_context if self.references: @@ -76,16 +69,6 @@ class ContainerNode(template.Node): content = '' else: content = contentlet.content - - if '{%' in content or '{{' in content: - try: - content = template.Template(contentlet.content, name=contentlet.name).render(context) - except template.TemplateSyntaxError, e: - if settings.DEBUG: - content = ('[Error parsing contentlet \'%s\': %s]' % (self.name, e)) - else: - content = settings.TEMPLATE_STRING_IF_INVALID - content = mark_safe(content) return content