예제 #1
0
 def test_slug_collisions_api_1(self):
     """ Checks for slug collisions on sibling pages - uses API to create pages
     """
     page1 = create_page('test page 1',
                         'nav_playground.html',
                         'en',
                         published=True)
     page1_1 = create_page('test page 1_1',
                           'nav_playground.html',
                           'en',
                           published=True,
                           parent=page1,
                           slug="foo")
     page1_2 = create_page('test page 1_2',
                           'nav_playground.html',
                           'en',
                           published=True,
                           parent=page1,
                           slug="foo")
     # both sibling pages has same slug, so both pages has an invalid slug
     self.assertFalse(
         is_valid_page_slug(page1_1, page1_1.parent, "en",
                            page1_1.get_slug("en"), page1_1.site))
     self.assertFalse(
         is_valid_page_slug(page1_2, page1_2.parent, "en",
                            page1_2.get_slug("en"), page1_2.site))
예제 #2
0
 def test_slug_collisions_api_2(self):
     """ Checks for slug collisions on root (not home) page and a home page child - uses API to create pages
     """
     page1 = create_page('test page 1',
                         'nav_playground.html',
                         'en',
                         published=True)
     page1_1 = create_page('test page 1_1',
                           'nav_playground.html',
                           'en',
                           published=True,
                           parent=page1,
                           slug="foo")
     page2 = create_page('test page 1_1',
                         'nav_playground.html',
                         'en',
                         published=True,
                         slug="foo")
     # Home page child has an invalid slug, while root page is ok. Root wins!
     self.assertFalse(
         is_valid_page_slug(page1_1, page1_1.parent, "en",
                            page1_1.get_slug("en"), page1_1.site))
     self.assertTrue(
         is_valid_page_slug(page2, page2.parent, "en", page2.get_slug("en"),
                            page2.site))
예제 #3
0
파일: page.py 프로젝트: nmurrin/django-cms
 def test_slug_collisions_api_2(self):
     """ Checks for slug collisions on root (not home) page and a home page child - uses API to create pages
     """
     page1 = create_page("test page 1", "nav_playground.html", "en", published=True)
     page1_1 = create_page("test page 1_1", "nav_playground.html", "en", published=True, parent=page1, slug="foo")
     page2 = create_page("test page 1_1", "nav_playground.html", "en", published=True, slug="foo")
     # Home page child has an invalid slug, while root page is ok. Root wins!
     self.assertFalse(is_valid_page_slug(page1_1, page1_1.parent, "en", page1_1.get_slug("en"), page1_1.site))
     self.assertTrue(is_valid_page_slug(page2, page2.parent, "en", page2.get_slug("en"), page2.site))
예제 #4
0
파일: page.py 프로젝트: nmurrin/django-cms
 def test_slug_collisions_api_1(self):
     """ Checks for slug collisions on sibling pages - uses API to create pages
     """
     page1 = create_page("test page 1", "nav_playground.html", "en", published=True)
     page1_1 = create_page("test page 1_1", "nav_playground.html", "en", published=True, parent=page1, slug="foo")
     page1_2 = create_page("test page 1_2", "nav_playground.html", "en", published=True, parent=page1, slug="foo")
     # both sibling pages has same slug, so both pages has an invalid slug
     self.assertFalse(is_valid_page_slug(page1_1, page1_1.parent, "en", page1_1.get_slug("en"), page1_1.site))
     self.assertFalse(is_valid_page_slug(page1_2, page1_2.parent, "en", page1_2.get_slug("en"), page1_2.site))
예제 #5
0
 def test_slug_collisions_api_2(self):
     """ Checks for slug collisions on root (not home) page and a home page child - uses API to create pages
     """
     page1 = create_page('test page 1', 'nav_playground.html', 'en',
                         published=True)
     page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
                           published=True, parent=page1, slug="foo")
     page2 = create_page('test page 1_1', 'nav_playground.html', 'en',
                         published=True, slug="foo")
     # Root (non home) page and child page has the same slug, both are invalid
     self.assertFalse(is_valid_page_slug(page1_1, page1_1.parent, "en", page1_1.get_slug("en"), page1_1.site))
     self.assertFalse(is_valid_page_slug(page2, page2.parent, "en", page2.get_slug("en"), page2.site))
예제 #6
0
 def test_slug_collisions_api_1(self):
     """ Checks for slug collisions on sibling pages - uses API to create pages
     """
     with SettingsOverride(CMS_MODERATOR=False):
         page1 = create_page('test page 1', 'nav_playground.html', 'en',
                             published=True)
         page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
                               published=True, parent=page1, slug="foo")
         page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
                               published=True, parent=page1, slug="foo")
         # both sibling pages has same slug, so both pages has an invalid slug
         self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
         self.assertFalse(is_valid_page_slug(page1_2,page1_2.parent,"en",page1_2.get_slug("en"),page1_2.site))
예제 #7
0
 def test_slug_collisions_api_2(self):
     """ Checks for slug collisions on root (not home) page and a home page child - uses API to create pages
     """
     with SettingsOverride(CMS_MODERATOR=False):
         page1 = create_page('test page 1', 'nav_playground.html', 'en',
                             published=True)
         page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
                               published=True, parent=page1, slug="foo")
         page2 = create_page('test page 1_1', 'nav_playground.html', 'en',
                               published=True, slug="foo")
         # Home page child has an invalid slug, while root page is ok. Root wins!
         self.assertFalse(is_valid_page_slug(page1_1,page1_1.parent,"en",page1_1.get_slug("en"),page1_1.site))
         self.assertTrue(is_valid_page_slug(page2,page2.parent,"en",page2.get_slug("en"),page2.site))
예제 #8
0
파일: forms.py 프로젝트: 42/django-cms
 def clean(self):
     cleaned_data = self.cleaned_data
     if 'slug' in cleaned_data.keys():
         slug = cleaned_data['slug']
     else:
         slug = ""
     
     page = self.instance
     lang = cleaned_data.get('language', None)
     # No language, can not go further, but validation failed already
     if not lang: 
         return cleaned_data
     
     if 'parent' not in cleaned_data:
         cleaned_data['parent'] = None
     parent = cleaned_data.get('parent', None)
     
     try:
         site = self.cleaned_data.get('site', Site.objects.get_current())
     except Site.DoesNotExist:
         site = None
         raise ValidationError("No site found for current settings.")
     
     if site and not is_valid_page_slug(page, parent, lang, slug, site):
         self._errors['slug'] = ErrorList([_('Another page with this slug already exists')])
         del cleaned_data['slug']
     return cleaned_data
예제 #9
0
 def clean(self):
     cleaned_data = self.cleaned_data
     if 'slug' in cleaned_data.keys():
         slug = cleaned_data['slug']
     else:
         slug = ""
     
     page = self.instance
     lang = cleaned_data.get('language', None)
     # No language, can not go further, but validation failed already
     if not lang: 
         return cleaned_data
     
     if 'parent' not in cleaned_data:
         cleaned_data['parent'] = None
     parent = cleaned_data.get('parent', None)
     
     try:
         site = self.cleaned_data.get('site', Site.objects.get_current())
     except Site.DoesNotExist:
         site = None
         raise ValidationError("No site found for current settings.")
     
     if site and not is_valid_page_slug(page, parent, lang, slug, site):
         self._errors['slug'] = ErrorList([_('Another page with this slug already exists')])
         del cleaned_data['slug']
     return cleaned_data
예제 #10
0
 def test_slug_collisions_api_3(self):
     """ Checks for slug collisions on children of a non root page - uses API to create pages
     """
     with SettingsOverride(CMS_MODERATOR=False):
         page1 = create_page('test page 1',
                             'nav_playground.html',
                             'en',
                             published=True)
         page1_1 = create_page('test page 1_1',
                               'nav_playground.html',
                               'en',
                               published=True,
                               parent=page1,
                               slug="foo")
         page1_1_1 = create_page('test page 1_1_1',
                                 'nav_playground.html',
                                 'en',
                                 published=True,
                                 parent=page1_1,
                                 slug="bar")
         page1_1_2 = create_page('test page 1_1_1',
                                 'nav_playground.html',
                                 'en',
                                 published=True,
                                 parent=page1_1,
                                 slug="bar")
         page1_2 = create_page('test page 1_2',
                               'nav_playground.html',
                               'en',
                               published=True,
                               parent=page1,
                               slug="bar")
         # Direct children of home has different slug so it's ok.
         self.assertTrue(
             is_valid_page_slug(page1_1, page1_1.parent, "en",
                                page1_1.get_slug("en"), page1_1.site))
         self.assertTrue(
             is_valid_page_slug(page1_2, page1_2.parent, "en",
                                page1_2.get_slug("en"), page1_2.site))
         # children of page1_1 has the same slug -> you lose!
         self.assertFalse(
             is_valid_page_slug(page1_1_1, page1_1_1.parent, "en",
                                page1_1_1.get_slug("en"), page1_1_1.site))
         self.assertFalse(
             is_valid_page_slug(page1_1_2, page1_1_2.parent, "en",
                                page1_1_2.get_slug("en"), page1_1_2.site))
예제 #11
0
파일: page.py 프로젝트: 11craft/django-cms
 def test_slug_collisions_api_3(self):
     """ Checks for slug collisions on children of a non root page - uses API to create pages
     """
     page1 = create_page('test page 1', 'nav_playground.html', 'en',
                         published=True)
     page1_1 = create_page('test page 1_1', 'nav_playground.html', 'en',
                           published=True, parent=page1, slug="foo")
     page1_1_1 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
                           published=True, parent=page1_1, slug="bar")
     page1_1_2 = create_page('test page 1_1_1', 'nav_playground.html', 'en',
                           published=True, parent=page1_1, slug="bar")
     page1_2 = create_page('test page 1_2', 'nav_playground.html', 'en',
                           published=True, parent=page1, slug="bar")
     # Direct children of home has different slug so it's ok.
     self.assertTrue(is_valid_page_slug(page1_1, page1_1.parent, "en", page1_1.get_slug("en"), page1_1.site))
     self.assertTrue(is_valid_page_slug(page1_2, page1_2.parent, "en", page1_2.get_slug("en"), page1_2.site))
     # children of page1_1 has the same slug -> you lose!
     self.assertFalse(is_valid_page_slug(page1_1_1, page1_1_1.parent, "en", page1_1_1.get_slug("en"), page1_1_1.site))
     self.assertFalse(is_valid_page_slug(page1_1_2, page1_1_2.parent, "en", page1_1_2.get_slug("en"), page1_1_2.site))
예제 #12
0
    def clean(self):
        cleaned_data = self.cleaned_data
        slug = cleaned_data.get('slug', '')

        page = self.instance
        lang = cleaned_data.get('language', None)
        # No language, can not go further, but validation failed already
        if not lang:
            return cleaned_data

        if 'parent' not in cleaned_data:
            cleaned_data['parent'] = None
        parent = cleaned_data.get('parent', None)

        try:
            site = self.cleaned_data.get('site', Site.objects.get_current())
        except Site.DoesNotExist:
            raise ValidationError("No site found for current settings.")

        if parent and parent.site != site:
            raise ValidationError("Site doesn't match the parent's page site")

        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors['slug'] = ErrorList(
                [_('Another page with this slug already exists')])
            del cleaned_data['slug']
        if self.instance and page.title_set.count():
            #Check for titles attached to the page makes sense only because
            #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
            #Looks like just a theoretical corner case
            try:
                title = page.get_title_obj(lang, fallback=False)
            except titlemodels.Title.DoesNotExist:
                title = None
            if title and not isinstance(title,
                                        titlemodels.EmptyTitle) and slug:
                oldslug = title.slug
                title.slug = slug
                title.save()
                try:
                    is_valid_url(title.path, page)
                except ValidationError:
                    exc = sys.exc_info()[0]
                    title.slug = oldslug
                    title.save()
                    if 'slug' in cleaned_data:
                        del cleaned_data['slug']
                    self._errors['slug'] = ErrorList(exc.messages)
        return cleaned_data
예제 #13
0
 def clean(self):
     cleaned_data = self.cleaned_data
     if 'slug' in cleaned_data.keys():
         slug = cleaned_data['slug']
     else:
         slug = ""
     page = self.instance
     lang = cleaned_data['language']
     if 'parent' not in cleaned_data:
         cleaned_data['parent'] = None
     parent = cleaned_data.get('parent', None)
     site = self.cleaned_data.get('site', Site.objects.get_current())
     if not is_valid_page_slug(page, parent, lang, slug, site):
         self._errors['slug'] = ErrorList([ugettext_lazy('Another page with this slug already exists')])
         del cleaned_data['slug']
     return cleaned_data
예제 #14
0
 def clean(self):
     cleaned_data = self.cleaned_data
     if "slug" in cleaned_data.keys():
         slug = cleaned_data["slug"]
     else:
         slug = ""
     page = self.instance
     lang = cleaned_data["language"]
     if "parent" not in cleaned_data:
         cleaned_data["parent"] = None
     parent = cleaned_data.get("parent", None)
     site = self.cleaned_data.get("site", Site.objects.get_current())
     if not is_valid_page_slug(page, parent, lang, slug, site):
         self._errors["slug"] = ErrorList([ugettext_lazy("Another page with this slug already exists")])
         del cleaned_data["slug"]
     return cleaned_data
예제 #15
0
    def clean(self):
        cleaned_data = self.cleaned_data
        slug = cleaned_data.get('slug', '')
        
        page = self.instance
        lang = cleaned_data.get('language', None)
        # No language, can not go further, but validation failed already
        if not lang:
            return cleaned_data

        if 'parent' not in cleaned_data:
            cleaned_data['parent'] = None
        parent = cleaned_data.get('parent', None)

        try:
            site = self.cleaned_data.get('site', Site.objects.get_current())
        except Site.DoesNotExist:
            raise ValidationError("No site found for current settings.")

        if parent and parent.site != site:
            raise ValidationError("Site doesn't match the parent's page site")

        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors['slug'] = ErrorList([_('Another page with this slug already exists')])
            del cleaned_data['slug']
        if self.instance and page.title_set.count():
            #Check for titles attached to the page makes sense only because
            #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
            #Looks like just a theoretical corner case
            title = page.get_title_obj(lang, fallback=False)
            if title and not isinstance(title, EmptyTitle) and slug:
                oldslug = title.slug
                title.slug = slug
                title.save()
                try:
                    is_valid_url(title.path, page)
                except ValidationError as exc:
                    title.slug = oldslug
                    title.save()
                    if 'slug' in cleaned_data:
                        del cleaned_data['slug']
                    if hasattr(exc, 'messages'):
                        errors = exc.messages
                    else:
                        errors = [force_unicode(exc.message)]
                    self._errors['slug'] = ErrorList(errors)
        return cleaned_data
예제 #16
0
    def clean(self):
        cleaned_data = self.cleaned_data

        if self._errors:
            # Form already has errors, best to let those be
            # addressed first.
            return cleaned_data

        slug = cleaned_data['slug']
        lang = cleaned_data['language']
        parent = cleaned_data.get('parent', None)
        site = self.cleaned_data.get('site', Site.objects.get_current())

        page = self.instance

        if parent and parent.site != site:
            raise ValidationError("Site doesn't match the parent's page site")

        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors['slug'] = ErrorList(
                [_('Another page with this slug already exists')])
            del cleaned_data['slug']

        if page and page.title_set.exists():
            #Check for titles attached to the page makes sense only because
            #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
            #Looks like just a theoretical corner case
            title = page.get_title_obj(lang, fallback=False)
            if title and not isinstance(title, EmptyTitle) and slug:
                oldslug = title.slug
                title.slug = slug
                title.save()
                try:
                    is_valid_url(title.path, page)
                except ValidationError as exc:
                    title.slug = oldslug
                    title.save()
                    if 'slug' in cleaned_data:
                        del cleaned_data['slug']
                    if hasattr(exc, 'messages'):
                        errors = exc.messages
                    else:
                        errors = [force_text(exc.message)]
                    self._errors['slug'] = ErrorList(errors)
        return cleaned_data
예제 #17
0
파일: forms.py 프로젝트: Aendra/django_vgv
    def clean(self):
        cleaned_data = self.cleaned_data

        if self._errors:
            # Form already has errors, best to let those be
            # addressed first.
            return cleaned_data

        slug = cleaned_data['slug']
        lang = cleaned_data['language']
        parent = cleaned_data.get('parent', None)
        site = self.cleaned_data.get('site', Site.objects.get_current())

        page = self.instance

        if parent and parent.site != site:
            raise ValidationError("Site doesn't match the parent's page site")

        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors['slug'] = ErrorList([_('Another page with this slug already exists')])
            del cleaned_data['slug']

        if page and page.title_set.count():
            #Check for titles attached to the page makes sense only because
            #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
            #Looks like just a theoretical corner case
            title = page.get_title_obj(lang, fallback=False)
            if title and not isinstance(title, EmptyTitle) and slug:
                oldslug = title.slug
                title.slug = slug
                title.save()
                try:
                    is_valid_url(title.path, page)
                except ValidationError as exc:
                    title.slug = oldslug
                    title.save()
                    if 'slug' in cleaned_data:
                        del cleaned_data['slug']
                    if hasattr(exc, 'messages'):
                        errors = exc.messages
                    else:
                        errors = [force_text(exc.message)]
                    self._errors['slug'] = ErrorList(errors)
        return cleaned_data
예제 #18
0
    def clean(self):
        cleaned_data = self.cleaned_data
        if 'slug' in cleaned_data.keys():
            slug = cleaned_data['slug']
        else:
            slug = ""

        page = self.instance
        lang = cleaned_data.get('language', None)
        # No language, can not go further, but validation failed already
        if not lang:
            return cleaned_data

        if 'parent' not in cleaned_data:
            cleaned_data['parent'] = None
        parent = cleaned_data.get('parent', None)

        try:
            site = self.cleaned_data.get('site', Site.objects.get_current())
        except Site.DoesNotExist:
            site = None
            raise ValidationError("No site found for current settings.")

        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors['slug'] = ErrorList(
                [_('Another page with this slug already exists')])
            del cleaned_data['slug']
        if self.cleaned_data['published'] and page.title_set.count():
            #Check for titles attached to the page makes sense only because
            #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
            #Looks like just a theoretical corner case
            title = page.get_title_obj(lang)
            if title:
                oldslug = title.slug
                title.slug = self.cleaned_data['slug']
                title.save()
                try:
                    is_valid_url(title.path, page)
                except ValidationError, e:
                    title.slug = oldslug
                    title.save()
                    del cleaned_data['published']
                    self._errors['published'] = ErrorList(e.messages)
예제 #19
0
 def clean(self):
     cleaned_data = self.cleaned_data
     if 'slug' in cleaned_data.keys():
         slug = cleaned_data['slug']
     else:
         slug = ""
     
     page = self.instance
     lang = cleaned_data.get('language', None)
     # No language, can not go further, but validation failed already
     if not lang: 
         return cleaned_data
     
     if 'parent' not in cleaned_data:
         cleaned_data['parent'] = None
     parent = cleaned_data.get('parent', None)
     
     try:
         site = self.cleaned_data.get('site', Site.objects.get_current())
     except Site.DoesNotExist:
         site = None
         raise ValidationError("No site found for current settings.")
     
     if site and not is_valid_page_slug(page, parent, lang, slug, site):
         self._errors['slug'] = ErrorList([_('Another page with this slug already exists')])
         del cleaned_data['slug']
     if self.cleaned_data['published'] and page.title_set.count():
         #Check for titles attached to the page makes sense only because
         #AdminFormsTests.test_clean_overwrite_url validates the form with when no page instance available
         #Looks like just a theoretical corner case
         title = page.get_title_obj(lang)
         if title:
             oldslug = title.slug
             title.slug = self.cleaned_data['slug']
             title.save()
             try:
                 is_valid_url(title.path,page)
             except ValidationError,e:
                 title.slug = oldslug
                 title.save()
                 del cleaned_data['published']
                 self._errors['published'] = ErrorList(e.messages)
예제 #20
0
    def clean(self):
        cleaned_data = self.cleaned_data
        if "slug" in cleaned_data.keys():
            slug = cleaned_data["slug"]
        else:
            slug = ""

        page = self.instance
        lang = cleaned_data["language"]

        if "parent" not in cleaned_data:
            cleaned_data["parent"] = None
        parent = cleaned_data.get("parent", None)

        try:
            site = self.cleaned_data.get("site", Site.objects.get_current())
        except Site.DoesNotExist:
            site = None
            raise ValidationError("No site found for current settings.")
        if site and not is_valid_page_slug(page, parent, lang, slug, site):
            self._errors["slug"] = ErrorList([ugettext_lazy("Another page with this slug already exists")])
            del cleaned_data["slug"]
        return cleaned_data