Permalink
Browse files

Fixed #6383 -- Rewriting url of page corrupted after save basic setti…

…ngs of page (#6470)
  • Loading branch information...
czpython committed Aug 6, 2018
1 parent 93559da commit 2923f0d919913e2cfc3b7aba09dd7e97b31ef21a
Showing with 51 additions and 4 deletions.
  1. +0 −1 CHANGELOG.txt
  2. +10 −3 cms/admin/forms.py
  3. +41 −0 cms/tests/test_page_admin.py
@@ -10,7 +10,6 @@
* Introduced Django 2.0 support.
* Introduced Django 2.1 support.
=== 3.5.2 (2018-04-11) ===
* Fixed a bug where shortcuts menu entry would stop working after toolbar reload
@@ -391,15 +391,15 @@ class ChangePageForm(BasePageForm):
def __init__(self, *args, **kwargs):
super(ChangePageForm, self).__init__(*args, **kwargs)
title_obj = self.instance.get_title_obj(
self.title_obj = self.instance.get_title_obj(
language=self._language,
fallback=False,
force_reload=True,
)
for field in self.translation_fields:
if field in self.fields:
self.fields[field].initial = getattr(title_obj, field)
self.fields[field].initial = getattr(self.title_obj, field)
def clean(self):
data = super(ChangePageForm, self).clean()
@@ -415,6 +415,10 @@ def clean(self):
data['path'] = ''
return data
if self.title_obj.has_url_overwrite:
data['path'] = self.title_obj.path
return data
if 'slug' not in self.fields:
# the {% edit_title_fields %} template tag
# allows users to edit specific fields for a translation.
@@ -450,7 +454,10 @@ def save(self, commit=True):
for field in self.translation_fields if field in data}
if 'path' in data:
# this field is managed manually
# The path key is set if
# the slug field is present in the form,
# or if the page being edited is the home page,
# or if the translation has a url override.
translation_data['path'] = data['path']
update_count = cms_page.update_translations(
@@ -1421,6 +1421,47 @@ def test_remove_overwrite_url(self):
response = self.client.get(endpoint)
self.assertContains(response, expected, html=True)
@override_settings(CMS_PERMISSION=False)
def test_rewrite_url_being_corrupted_after_save_basic_settings(self):
superuser = self.get_superuser()
parent_page = create_page(
'parent',
'nav_playground.html',
language='en',
published=True,
)
child_page = create_page(
'child',
'nav_playground.html',
language='en',
published=True,
parent=parent_page,
)
with self.login_user_context(superuser):
endpoint = self.get_admin_url(Page, 'advanced', child_page.pk)
self.client.post(
endpoint,
{
'overwrite_url': 'rewrited',
'template': child_page.template,
},
)
child_page.publish('en')
endpoint = self.get_admin_url(Page, 'change', child_page.pk)
self.client.post(
endpoint,
{
'language': 'en',
'title': 'child',
'slug': 'child',
},
)
title = child_page.get_title_obj('en', fallback=False)
self.assertEqual(title.path, 'rewrited')
def test_advanced_settings_form(self):
superuser = self.get_superuser()
page = create_page('Page 1', 'nav_playground.html', 'en')

0 comments on commit 2923f0d

Please sign in to comment.