Skip to content
Browse files

Merge pull request #989 from ojii/fix-988

Fix 988
  • Loading branch information...
2 parents 6ef4ed6 + 9a28283 commit 4d6e1b02538411a8e41da0456bd249bcfba613b3 @chrisglass chrisglass committed Sep 2, 2011
Showing with 95 additions and 2 deletions.
  1. +10 −2 cms/models/managers.py
  2. +85 −0 cms/tests/admin.py
View
12 cms/models/managers.py
@@ -188,13 +188,15 @@ def set_or_create(self, request, page, form, language):
base_fields = [
'slug',
'title',
- 'application_urls',
- 'redirect',
'meta_description',
'meta_keywords',
'page_title',
'menu_title'
]
+ advanced_fields = [
+ 'application_urls',
+ 'redirect',
+ ]
cleaned_data = form.cleaned_data
try:
obj = self.get(page=page, language=language)
@@ -210,6 +212,10 @@ def set_or_create(self, request, page, form, language):
if overwrite_url:
data['has_url_overwrite'] = True
data['path'] = overwrite_url
+ for field in advanced_fields:
+ value = cleaned_data.get(field, None)
+ if value:
+ data[field] = value
return self.create(**data)
for name in base_fields:
@@ -219,6 +225,8 @@ def set_or_create(self, request, page, form, language):
overwrite_url = cleaned_data.get('overwrite_url', None)
obj.has_url_overwrite = bool(overwrite_url)
obj.path = overwrite_url
+ for field in advanced_fields:
+ setattr(obj, field, cleaned_data.get(field, None))
obj.save()
return obj
View
85 cms/tests/admin.py
@@ -158,6 +158,91 @@ def test_edit_does_not_reset_page_adv_fields(self):
self.assertEqual(page.reverse_id, REVERSE_ID)
title = page.get_title_obj()
self.assertEqual(title.overwrite_url, None)
+
+ def test_edit_does_not_reset_apphook(self):
+ """
+ Makes sure that if a non-superuser with no rights to edit advanced page
+ fields edits a page, those advanced fields are not touched.
+ """
+ OLD_PAGE_NAME = 'Test Page'
+ NEW_PAGE_NAME = 'Test page 2'
+ REVERSE_ID = 'Test'
+ APPLICATION_URLS = 'project.sampleapp.urls'
+
+ admin, normal_guy = self._get_guys()
+
+ site = Site.objects.get(pk=1)
+
+ # The admin creates the page
+ page = create_page(OLD_PAGE_NAME, "nav_playground.html", "en",
+ site=site, created_by=admin)
+ page.reverse_id = REVERSE_ID
+ page.save()
+ title = page.get_title_obj()
+ title.has_url_overwrite = True
+ title.application_urls = APPLICATION_URLS
+ title.save()
+
+ self.assertEqual(page.get_title(), OLD_PAGE_NAME)
+ self.assertEqual(page.reverse_id, REVERSE_ID)
+ self.assertEqual(title.application_urls, APPLICATION_URLS)
+
+ # The user edits the page (change the page name for ex.)
+ page_data = {
+ 'title': NEW_PAGE_NAME,
+ 'slug': page.get_slug(),
+ 'language': title.language,
+ 'site': page.site.pk,
+ 'template': page.template,
+ }
+ # required only if user haves can_change_permission
+ page_data['pagepermission_set-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-MAX_NUM_FORMS'] = 0
+ page_data['pagepermission_set-2-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
+
+ with self.login_user_context(normal_guy):
+ resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
+ follow=True)
+ self.assertEqual(resp.status_code, 200)
+ self.assertTemplateNotUsed(resp, 'admin/login.html')
+ page = Page.objects.get(pk=page.pk)
+
+ self.assertEqual(page.get_title(), NEW_PAGE_NAME)
+ self.assertEqual(page.reverse_id, REVERSE_ID)
+ title = page.get_title_obj()
+ self.assertEqual(title.application_urls, APPLICATION_URLS)
+
+ # The admin edits the page (change the page name for ex.)
+ page_data = {
+ 'title': OLD_PAGE_NAME,
+ 'slug': page.get_slug(),
+ 'language': title.language,
+ 'site': page.site.pk,
+ 'template': page.template,
+ 'reverse_id': page.reverse_id,
+ }
+ # required only if user haves can_change_permission
+ page_data['pagepermission_set-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-MAX_NUM_FORMS'] = 0
+ page_data['pagepermission_set-2-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
+
+ with self.login_user_context(admin):
+ resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
+ follow=True)
+ self.assertEqual(resp.status_code, 200)
+ self.assertTemplateNotUsed(resp, 'admin/login.html')
+ page = Page.objects.get(pk=page.pk)
+
+ self.assertEqual(page.get_title(), OLD_PAGE_NAME)
+ self.assertEqual(page.reverse_id, REVERSE_ID)
+ title = page.get_title_obj()
+ self.assertEqual(title.application_urls, '')
def test_delete(self):
admin = self._get_guys(True)

0 comments on commit 4d6e1b0

Please sign in to comment.
Something went wrong with that request. Please try again.