Skip to content

Commit d2c911c

Browse files
committed
Improve reusability of ContentProxy methods
1 parent a3cdeee commit d2c911c

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

feincms/models.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,24 @@ def __unicode__(self):
8787
class ContentProxy(object):
8888
def __init__(self, item):
8989
item._needs_content_types()
90-
9190
self.item = item
9291
self.media_cache = None
9392

94-
self.content_type_counts = counts = self._fetch_content_type_counts(item.pk)
93+
self.content_type_counts = self._fetch_content_type_counts(item.pk)
94+
self.content_type_instances = self._fetch_content_type_instances(
95+
self.content_type_counts)
96+
97+
def _fetch_content_type_counts(self, pk):
98+
counts = self._fetch_content_type_count_helper(self.item.pk)
9599

96100
empty_inherited_regions = set()
97-
for region in item.template.regions:
101+
for region in self.item.template.regions:
98102
if region.inherited and not counts.get(region.key):
99103
empty_inherited_regions.add(region.key)
100104

101105
if empty_inherited_regions:
102-
for parent in item.get_ancestors(ascending=True).values_list('pk', flat=True):
103-
parent_counts = self._fetch_content_type_counts(
106+
for parent in self.item.get_ancestors(ascending=True).values_list('pk', flat=True):
107+
parent_counts = self._fetch_content_type_count_helper(
104108
parent, regions=tuple(empty_inherited_regions))
105109

106110
counts.update(parent_counts)
@@ -110,9 +114,9 @@ def __init__(self, item):
110114
if not empty_inherited_regions:
111115
break
112116

113-
self.content_type_instances = self._fetch_content_type_instances(counts)
117+
return counts
114118

115-
def _fetch_content_type_counts(self, pk, regions=None):
119+
def _fetch_content_type_count_helper(self, pk, regions=None):
116120
"""
117121
Returns a structure describing which content types exist for the object
118122
with the given primary key.

0 commit comments

Comments
 (0)