Permalink
Browse files

Fixed page resolving with CMS_FLAT_URLS (+tests)

  • Loading branch information...
1 parent feab021 commit 075c076c1a58486c2cc352844807d502f852c8ac Jonas Obrist committed Dec 27, 2010
Showing with 50 additions and 16 deletions.
  1. +35 −2 cms/tests/page.py
  2. +13 −10 cms/utils/page_resolver.py
  3. +2 −4 cms/views.py
View
37 cms/tests/page.py
@@ -4,7 +4,7 @@
from cms.sitemaps import CMSSitemap
from cms.tests.base import CMSTestCase, URL_CMS_PAGE, URL_CMS_PAGE_ADD, \
URL_CMS_PAGE_CHANGE
-from cms.tests.util.context_managers import LanguageOverride
+from cms.tests.util.context_managers import LanguageOverride, SettingsOverride
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
@@ -257,4 +257,37 @@ def test_13_edit_page_other_site_and_language(self):
self.assertRedirects(response, URL_CMS_PAGE)
page = Page.objects.get(title_set__slug=page_data['slug'])
with LanguageOverride(TESTLANG):
- self.assertEqual(page.get_title(), 'changed title')
+ self.assertEqual(page.get_title(), 'changed title')
+
+ def test_14_flat_urls(self):
+ with SettingsOverride(CMS_FLAT_URLS=True):
+ home_slug = "home"
+ child_slug = "child"
+ grandchild_slug = "grandchild"
+ home = self.new_create_page(
+ title=home_slug,
+ published=True,
+ in_navigation=True
+ )
+ home.publish()
+ child = self.new_create_page(
+ parent_page=home,
+ title=child_slug,
+ published=True,
+ in_navigation=True
+ )
+ child.publish()
+ grandchild = self.new_create_page(
+ parent_page=child,
+ title=grandchild_slug,
+ published=True,
+ in_navigation=True
+ )
+ grandchild.publish()
+ response = self.client.get(home.get_absolute_url())
+ self.assertEqual(response.status_code, 200)
+ response = self.client.get(child.get_absolute_url())
+ self.assertEqual(response.status_code, 200)
+ response = self.client.get(grandchild.get_absolute_url())
+ self.assertEqual(response.status_code, 200)
+ self.assertFalse(child.get_absolute_url() in grandchild.get_absolute_url())
View
23 cms/utils/page_resolver.py
@@ -81,16 +81,19 @@ def get_page_from_request(request, use_path=None):
# title_set__path=path should be clear, get the pages where the path of the
# title object is equal to our path.
- q = Q(title_set__path=path)
- if home:
- # if we have a home, also search for all paths prefixed with the
- # home slug that are on the same tree as home, since home isn't ussually
- # called with it's slug, thus it's children don't have the home bit in
- # the request either, thus we need to re-add it.
- q2 = Q()
- q2 = Q(title_set__path='%s/%s' % (home.get_slug(), path))
- q2 &= Q(tree_id=home.tree_id)
- q |= q2
+ if settings.CMS_FLAT_URLS:
+ q = Q(title_set__slug=path)
+ else:
+ q = Q(title_set__path=path)
+ if home:
+ # if we have a home, also search for all paths prefixed with the
+ # home slug that are on the same tree as home, since home isn't ussually
+ # called with it's slug, thus it's children don't have the home bit in
+ # the request either, thus we need to re-add it.
+ q2 = Q()
+ q2 = Q(title_set__path='%s/%s' % (home.get_slug(), path))
+ q2 &= Q(tree_id=home.tree_id)
+ q |= q2
# TODO: We should probably get rid of this odd DB-Gettext thingy, no idea
# how and why this should work
View
6 cms/views.py
@@ -1,18 +1,16 @@
from cms.apphook_pool import apphook_pool
-from cms.appresolver import applications_page_check, get_app_urls
+from cms.appresolver import get_app_urls
from cms.utils import get_template_from_request, get_language_from_request
from cms.utils.i18n import get_fallback_languages
from cms.utils.page_resolver import get_page_from_request
from django.conf import settings, settings as django_settings
-from django.conf.urls.defaults import patterns, include
-from django.core.exceptions import ImproperlyConfigured
+from django.conf.urls.defaults import patterns
from django.core.urlresolvers import resolve, Resolver404
from django.db.models.query_utils import Q
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.utils.http import urlquote
-from django.utils.importlib import import_module
def _handle_no_page(request, slug):

1 comment on commit 075c076

@gleb-chipiga

Thanks. Very quickly fixed.

Please sign in to comment.