- def __init__(self, contentlets, references):
- self.contentlets = dict(((c.name, c) for c in contentlets))
- self.references = dict((((c.name, ContentType.objects.get_for_id(c.content_type_id)), c) for c in references))
+ def __init__(self, page):
+ self.page = page
+
+ def get_contentlets(self):
+ if not hasattr(self, '_contentlets'):
+ self._contentlets = dict(((c.name, c) for c in self.page.contentlets.all()))
+ return self._contentlets
+
+ def get_references(self):
+ if not hasattr(self, '_references'):
+ references = self.page.contentreferences.all()
+ self._references = {}
+ contents = {}
+ for c in references:
+ ct = ContentType.objects.get_for_id(c.content_type_id)
+ self.references[(c.name, ct)] = c
+ contents.setdefault(ct, {})[c.content_id] = c
+
+ for ct in contents:
+ objs = ct.model_class().objects.filter(pk__in=contents[ct])
+ for obj in objs:
+ contents[ct][obj.pk].content = obj
+ return self._references