Permalink
Browse files

LUN-368 -- refactoring after code review

  • Loading branch information...
1 parent 439bf6d commit 7db291d72328dadaae7d3a6a454db7e796bcd34c Marcel Cojocaru committed Jan 31, 2013
Showing with 5 additions and 9 deletions.
  1. +3 −5 cms_templates/loader.py
  2. +1 −1 cms_templates/middleware.py
  3. +1 −3 cms_templates/restricted_admin_decorators.py
@@ -5,10 +5,8 @@
class CmsTemplatesLoader(Loader):
def load_and_store_template(self, template_name, cache_key, site, **params):
- if params.has_key('sites__in'):
- site_ids = params['sites__in'] + [s.id for s in Site.objects.filter(name__in=shared_sites)]
- return super(CmsTemplatesLoader, self).load_and_store_template(
- template_name, cache_key, site, sites__in=site_ids)
+ if 'sites__in' in params:
+ shared_ids = (s.id for s in Site.objects.filter(name__in=shared_sites).distinct())
+ params['sites__in'].extend(shared_ids)
return super(CmsTemplatesLoader, self).load_and_store_template(
template_name, cache_key, site, **params)
-
@@ -64,7 +64,7 @@ class DBTemplatesMiddleware(object):
def process_request(self, request):
site_id = request.session.get('cms_admin_site', settings.SITE_ID)
- t = get_restricted_instances(Template, site_id, shared_sites, include_orphan)
+ t = get_restricted_instances(Template, site_id, shared_sites)
CMS_TEMPLATES.value = [(templ.name, templ.name) for templ in t]
if not CMS_TEMPLATES.value:
CMS_TEMPLATES.value = [('dummy',
@@ -112,7 +112,7 @@ def __change_view(self, request, object_id, extra_context=None):
return cls
return _change_view
-def get_restricted_instances(model, site_id=None, shared_sites=(), include_orphan=False):
+def get_restricted_instances(model, site_id=None, shared_sites=()):
if not issubclass(model, Model):
raise TypeError('%s should be a django model.' % model.__name__)
@@ -122,6 +122,4 @@ def get_restricted_instances(model, site_id=None, shared_sites=(), include_orpha
f = Q(sites=Site.objects.get_current())
if shared_sites:
f |= Q(sites__name__in=shared_sites)
- if include_orphan:
- f |= Q(sites__isnull=True)
return model.objects.filter(f).distinct()

0 comments on commit 7db291d

Please sign in to comment.