Permalink
Browse files

Review and merge unique template used when duplicates are stored (LUN…

…-368)
  • Loading branch information...
2 parents 04fa1cd + 7db291d commit 741c192d423656ab39aa6fbb66e8f0b94b41847b Bogdan Hodorog committed Feb 1, 2013
Showing with 6 additions and 7 deletions.
  1. +4 −2 cms_templates/loader.py
  2. +1 −2 cms_templates/middleware.py
  3. +1 −3 cms_templates/restricted_admin_decorators.py
View
@@ -5,6 +5,8 @@
class CmsTemplatesLoader(Loader):
def load_and_store_template(self, template_name, cache_key, site, **params):
- site_ids = [s.id for s in Site.objects.filter(name__in=shared_sites)] + [site.id]
+ 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, sites__in=site_ids)
+ template_name, cache_key, site, **params)
@@ -64,8 +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 741c192

Please sign in to comment.