Permalink
Browse files

path building signals should respect overwritten urls.

  • Loading branch information...
1 parent 1f3e638 commit 895739c0473df084272f946193c0d30c5e0fa255 @stephrdev stephrdev committed Oct 5, 2011
Showing with 37 additions and 7 deletions.
  1. +9 −6 cms/signals.py
  2. +28 −1 cms/tests/page.py
View
@@ -49,12 +49,14 @@ def update_title(title):
if title.page.is_home():
title.path = ''
- else:
+ elif not title.has_url_overwrite:
title.path = u'%s' % slug
- if parent_page_id:
- parent_title = Title.objects.get_title(parent_page_id, language=title.language, language_fallback=True)
- if parent_title:
- title.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/")
+
+ if parent_page_id:
+ parent_title = Title.objects.get_title(parent_page_id,
+ language=title.language, language_fallback=True)
+ if parent_title:
+ title.path = (u'%s/%s' % (parent_title.path, slug)).lstrip("/")
def pre_save_title(instance, raw, **kwargs):
"""Save old state to instance and setup path
@@ -91,7 +93,8 @@ def post_save_title(instance, raw, created, **kwargs):
page__lft__gt=instance.page.lft,
page__rght__lt=instance.page.rght,
page__tree_id__exact=instance.page.tree_id,
- language=instance.language
+ language=instance.language,
+ has_url_overwrite=False,
).order_by('page__tree_id', 'page__parent', 'page__lft')
for descendant_title in descendant_titles:
View
@@ -505,7 +505,34 @@ def test_page_urls(self):
page3 = self.move_page(page3, page4)
self.assertEqual(page3.get_absolute_url(),
self.get_pages_root()+'test-page-4/test-page-3/')
-
+
+ def test_page_overwrite_urls(self):
+ page1 = create_page('test page 1', 'nav_playground.html', 'en',
+ published=True)
+
+ page2 = create_page('test page 2', 'nav_playground.html', 'en',
+ published=True, parent=page1)
+
+ page3 = create_page('test page 3', 'nav_playground.html', 'en',
+ published=True, parent=page2, overwrite_url='i-want-another-url')
+
+ self.assertEqual(page2.get_absolute_url(),
+ self.get_pages_root()+'test-page-2/')
+ self.assertEqual(page3.get_absolute_url(),
+ self.get_pages_root()+'i-want-another-url/')
+
+ title2 = page2.title_set.get()
+ title2.slug = 'page-test-2'
+ title2.save()
+
+ page2 = Page.objects.get(pk=page2.pk)
+ page3 = Page.objects.get(pk=page3.pk)
+
+ self.assertEqual(page2.get_absolute_url(),
+ self.get_pages_root()+'page-test-2/')
+ self.assertEqual(page3.get_absolute_url(),
+ self.get_pages_root()+'i-want-another-url/')
+
def test_home_slug_not_accessible(self):
with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
page = create_page('page', 'nav_playground.html', 'en', published=True)

0 comments on commit 895739c

Please sign in to comment.