Permalink
Browse files

Make page_resolver.get_page_queryset_from_path multisite-aware

  • Loading branch information...
1 parent 35ca58a commit 902b5a6a8a7c3732157ccbb0e995a6b7ec637bd8 @yakky yakky committed Sep 14, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 cms/utils/page_resolver.py
View
@@ -18,16 +18,17 @@
ADMIN_PAGE_RE = re.compile(ADMIN_PAGE_RE_PATTERN)
-def get_page_queryset_from_path(path, preview=False):
+def get_page_queryset_from_path(path, preview=False, site=None):
""" Returns a queryset of pages corresponding to the path given
In may returns None or a single page is no page is present or root path is given
"""
if 'django.contrib.admin' in settings.INSTALLED_APPS:
admin_base = reverse('admin:index').lstrip('/')
else:
admin_base = None
-
- site = Site.objects.get_current()
+
+ if not site:
+ site = Site.objects.get_current()
# Check if this is called from an admin request
if admin_base and path.startswith(admin_base):
# if so, get the page ID to query the page
@@ -47,10 +48,13 @@ def get_page_queryset_from_path(path, preview=False):
else:
pages = Page.objects.public()
+ # PageQuerySet.published filter on page site.
+ # We have to explicitly filter on site only in preview mode
+ # we can skip pages.filter
if not preview:
- pages = pages.published()
-
- pages = pages.filter(site=site)
+ pages = pages.published(site)
+ else:
+ pages = pages.filter(site_id=site.pk)
# Check if there are any pages
if not pages.all_root().exists():

0 comments on commit 902b5a6

Please sign in to comment.