X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/1b86deeeaf9c98d994e95b983c44a82e004275b0..8d5b1f789ed643ac9582398b370e6cf5137b8a6b:/philo/templatetags/containers.py diff --git a/philo/templatetags/containers.py b/philo/templatetags/containers.py index 2c55034..11ccd88 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,31 @@ 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 + + contentlet_specs, contentreference_specs = page.template.containers + contentlets = page.contentlets.filter(name__in=contentlet_specs) + q = Q() + for name, ct in contentreference_specs.items(): + q |= Q(name=name, content_type=ct) + references = page.contentreferences.filter(q) + + container_context = ContainerContext(contentlets, references) context.render_context[CONTAINER_CONTEXT_KEY] = container_context if self.references: