Repository: django-cms/django-cms

Issue:
"Overwrite URL" overwritten when you change basic settings.
Hi, I don't know if this the expected behaviour, but when you change the basic page settings, whatever value you've put in the overwrite URL is deleted. This has been a problem for users who just wanted to change the meta description on the basic settings form, not the URL.

This behaviour stems from https://github.com/divio/django-cms/blob/develop/cms/models/managers.py#L203 , the code goes:

``` python
overwrite_url = cleaned_data.get('overwrite_url', None)
obj.has_url_overwrite = bool(overwrite_url)
obj.path = overwrite_url
```

Whereas I think it should say:

``` python
if 'overwrite_url' in cleaned_data:
    overwrite_url = cleaned_data.get('overwrite_url', None)
    obj.has_url_overwrite = bool(overwrite_url)
    obj.path = overwrite_url
```

So `Title.path` and `Title.overwrite_url` are only set/reset if present in the form.



Discussion:

Resolving patch:
diff --git a/cms/models/managers.py b/cms/models/managers.py
--- a/cms/models/managers.py
+++ b/cms/models/managers.py
@@ -200,9 +200,10 @@ def set_or_create(self, request, page, form, language):
                 value = cleaned_data.get(name, None)
                 setattr(obj, name, value)
         if page.has_advanced_settings_permission(request):
-            overwrite_url = cleaned_data.get('overwrite_url', None)
-            obj.has_url_overwrite = bool(overwrite_url)
-            obj.path = overwrite_url
+            if 'overwrite_url' in cleaned_data:
+                overwrite_url = cleaned_data.get('overwrite_url', None)
+                obj.has_url_overwrite = bool(overwrite_url)
+                obj.path = overwrite_url
             for field in advanced_fields:
                 if field in form.base_fields:
                     value = cleaned_data.get(field, None)


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -136,7 +136,6 @@ def test_edit_does_not_reset_page_adv_fields(self):
             'pagepermission_set-2-MAX_NUM_FORMS': 0
         }
         # required only if user haves can_change_permission
-
         with self.login_user_context(normal_guy):
             resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
                                     follow=True)
@@ -149,22 +148,21 @@ def test_edit_does_not_reset_page_adv_fields(self):
             title = page.get_title_obj()
             self.assertEqual(title.overwrite_url, OVERRIDE_URL)
 
-            # 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,
-                'pagepermission_set-TOTAL_FORMS': 0,  # required only if user haves can_change_permission
-                'pagepermission_set-INITIAL_FORMS': 0,
-                'pagepermission_set-MAX_NUM_FORMS': 0,
-                'pagepermission_set-2-TOTAL_FORMS': 0,
-                'pagepermission_set-2-INITIAL_FORMS': 0,
-                'pagepermission_set-2-MAX_NUM_FORMS': 0
-            }
-
+        # 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,
+            'pagepermission_set-TOTAL_FORMS': 0,  # required only if user haves can_change_permission
+            'pagepermission_set-INITIAL_FORMS': 0,
+            'pagepermission_set-MAX_NUM_FORMS': 0,
+            'pagepermission_set-2-TOTAL_FORMS': 0,
+            'pagepermission_set-2-INITIAL_FORMS': 0,
+            'pagepermission_set-2-MAX_NUM_FORMS': 0
+        }
         with self.login_user_context(admin_user):
             resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
                                     follow=True)
@@ -175,7 +173,7 @@ def test_edit_does_not_reset_page_adv_fields(self):
             self.assertEqual(page.get_title(), OLD_PAGE_NAME)
             self.assertEqual(page.reverse_id, REVERSE_ID)
             title = page.get_title_obj()
-            self.assertEqual(title.overwrite_url, None)
+            self.assertEqual(title.overwrite_url, OVERRIDE_URL)
 
     def test_edit_does_not_reset_apphook(self):
         """