Repository: django-cms/django-cms

Issue:
Error when creating second page with same title/slug
I am on Release Candidate 2. 

I have a page with title "Question 5" . I add another page with the same title, "Question 5", which works fine, but when trying to load the second page, get the following error. Is it allowed to have two pages with same title, and thus also slug ? 

```
Traceback (most recent call last):
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
    return self.application(environ, start_response)
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
    response = self.get_response(request)
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/core/handlers/base.py", line 217, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/gcc538/code/env-geoportail/src/django-cms/cms/views.py", line 74, in details
    page = get_page_from_request(request, use_path=slug)
  File "/Users/gcc538/code/env-geoportail/src/django-cms/cms/utils/page_resolver.py", line 138, in get_page_from_request
    page = get_page_from_path(path, preview, draft)
  File "/Users/gcc538/code/env-geoportail/src/django-cms/cms/utils/page_resolver.py", line 91, in get_page_from_path
    page = page_qs.get()
  File "/Users/gcc538/code/env-geoportail/lib/python2.7/site-packages/django/db/models/query.py", line 407, in get
    (self.model._meta.object_name, num))
MultipleObjectsReturned: get() returned more than one Page -- it returned 2!

```



Discussion:
This should not be possible. Can you show the page tree?

Can you post the exact steps you took to reproduce this?

Okay, the screencast explains about as good as I can : 
![untitled](https://cloud.githubusercontent.com/assets/2540428/2643101/ed346d1c-bf14-11e3-8d45-6dfcb57b09c5.gif)

Hold on, still have problems with getting pip to install the latest RC2 

Okay, I have 3.0c2 


Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -295,7 +295,17 @@ def get_form(self, request, obj=None, **kwargs):
             self.inlines = []
             for name in ['slug', 'title']:
                 form.base_fields[name].initial = u''
-            form.base_fields['parent'].initial = request.GET.get('target', None)
+            if 'target' in request.GET:
+                target = request.GET['target']
+                if 'position' in request.GET:
+                    position = request.GET['position']
+                    if position == 'last-child' or position == 'first-child':
+                        form.base_fields['parent'].initial = request.GET.get('target', None)
+                    else:
+                        sibling = Page.objects.get(pk=target)
+                        form.base_fields['parent'].initial = sibling.parent_id
+                else:
+                    form.base_fields['parent'].initial = request.GET.get('target', None)
             form.base_fields['site'].initial = request.session.get('cms_admin_site', None)
         return form
 


Test patch:
diff --git a/cms/tests/page.py b/cms/tests/page.py
--- a/cms/tests/page.py
+++ b/cms/tests/page.py
@@ -126,6 +126,28 @@ def test_slug_collision(self):
             self.assertTrue(response.request['PATH_INFO'].endswith(URL_CMS_PAGE_ADD))
             self.assertContains(response, '<ul class="errorlist"><li>Another page with this slug already exists</li></ul>')
 
+    def test_child_slug_collision(self):
+        """
+        Test a slug collision
+        """
+        api.create_page("home", 'nav_playground.html', "en")
+        page = api.create_page("page", 'nav_playground.html', "en")
+        subPage = api.create_page("subpage", 'nav_playground.html', "en", parent=page)
+        superuser = self.get_superuser()
+        with self.login_user_context(superuser):
+
+            response = self.client.get(URL_CMS_PAGE_ADD+"?target=%s&position=right&site=1" % subPage.pk)
+            self.assertContains(response, '<input id="id_parent" name="parent" type="hidden" value="%s" />' % page.pk)
+
+            page_data = self.get_new_page_data(page.pk)
+            page_data['slug'] = 'subpage'
+            response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+
+            self.assertEqual(response.status_code, 200)
+            self.assertTrue(response.request['PATH_INFO'].endswith(URL_CMS_PAGE_ADD))
+            self.assertContains(response, '<ul class="errorlist"><li>Another page with this slug already exists</li></ul>')
+
+
     def test_get_available_slug_recursion(self):
         """ Checks cms.utils.page.get_available_slug for infinite recursion
         """