Exemplo n.º 1
0
 def clean_overwrite_url(self):
     if 'overwrite_url' in self.fields:
         url = self.cleaned_data['overwrite_url']
         if url:
             if not any_path_re.match(url):
                 raise forms.ValidationError(_('Invalid URL, use /my/url format.'))
     return url
Exemplo n.º 2
0
 def clean_overwrite_url(self):
     url = self.cleaned_data['overwrite_url']
     if url:
         if not any_path_re.match(url):
             raise forms.ValidationError(
                 _('Invalid URL, use /my/url format.'))
     return url
Exemplo n.º 3
0
 def clean_overwrite_url(self):
     if 'overwrite_url' in self.fields:
         url = self.cleaned_data['overwrite_url']
         if url:
             if not any_path_re.match(url):
                 raise forms.ValidationError(_('Invalid URL, use /my/url format.'))
             if get_page_from_path(url.strip('/')):
                 raise forms.ValidationError(_('Page with redirect url %r already exist') % url)
     return url
Exemplo n.º 4
0
 def clean_overwrite_url(self):
     if 'overwrite_url' in self.fields:
         url = self.cleaned_data['overwrite_url']
         if url:
             if not any_path_re.match(url):
                 raise forms.ValidationError(_('Invalid URL, use /my/url format.'))
             page = get_page_from_path(url.strip('/'))
             if page and page.pk != self.instance.pk:
                 raise forms.ValidationError(_('Page with redirect url %r already exist') % url)
     return url
Exemplo n.º 5
0
 def clean_overwrite_url(self):
     if "overwrite_url" in self.fields:
         url = self.cleaned_data["overwrite_url"]
         if url:
             if not any_path_re.match(url):
                 raise forms.ValidationError(_("Invalid URL, use /my/url format."))
             page = get_page_from_path(url.strip("/"))
             if page and page.pk != self.instance.pk:
                 raise forms.ValidationError(_("Page with redirect url %r already exist") % url)
     return url
Exemplo n.º 6
0
def is_valid_url(url, instance, create_links=True, site=None):
    """ Checks for conflicting urls
    """
    page_root = urllib.unquote(reverse("pages-root"))
    if url and url != page_root:
        # Url sanity check via regexp
        if not any_path_re.match(url):
            raise ValidationError(_('Invalid URL, use /my/url format.'))
        # We only check page FK to site object to allow is_valid_url check on
        # incomplete Page instances
        if not site and instance.site_id:
            site = instance.site
        # Retrieve complete queryset of pages with corresponding URL
        # This uses the same resolving function as ``get_page_from_path``
        if url.startswith(page_root):
            url = url[len(page_root):]
        page_qs = get_page_queryset_from_path(url.strip('/'), site=site)
        url_clashes = []
        # If queryset has pages checks for conflicting urls
        if page_qs is not None:
            # If single page is returned create a list for interface compat
            if isinstance(page_qs, Page):
                page_qs = [page_qs]
            for page in page_qs:
                # Every page in the queryset except the current one is a conflicting page
                # We have to exclude both copies of the page
                if page and page.publisher_public.pk != instance.pk:
                    if create_links:
                        # Format return message with page url
                        url_clashes.append(
                            '<a href="%(page_url)s%(pk)s" target="_blank">%(page_title)s</a>'
                            % {
                                'page_url':
                                reverse('admin:cms_page_changelist'),
                                'pk': page.pk,
                                'page_title': force_unicode(page),
                            })
                    else:
                        # Just return the page name
                        url_clashes.append("'%s'" % page)
            if url_clashes:
                # If clashing pages exist raise the exception
                raise ValidationError(
                    mark_safe(
                        ungettext_lazy(
                            'Page %(pages)s has the same url \'%(url)s\' as current page "%(instance)s".',
                            'Pages %(pages)s have the same url \'%(url)s\' as current page "%(instance)s".',
                            len(url_clashes)) % {
                                'pages': ', '.join(url_clashes),
                                'url': url,
                                'instance': instance
                            }))
    return True
Exemplo n.º 7
0
def is_valid_url(url, instance, create_links=True, site=None):
    """ Checks for conflicting urls
    """
    page_root = unquote(reverse("pages-root"))
    if url and url != page_root:
        # Url sanity check via regexp
        if not any_path_re.match(url):
            raise ValidationError(_("Invalid URL, use /my/url format."))
            # We only check page FK to site object to allow is_valid_url check on
        # incomplete Page instances
        if not site and instance.site_id:
            site = instance.site
            # Retrieve complete queryset of pages with corresponding URL
        # This uses the same resolving function as ``get_page_from_path``
        if url.startswith(page_root):
            url = url[len(page_root) :]
        page_qs = get_page_queryset_from_path(url.strip("/"), site=site, draft=instance.publisher_is_draft)
        url_clashes = []
        # If queryset has pages checks for conflicting urls
        for page in page_qs:
            # Every page in the queryset except the current one is a conflicting page
            # We have to exclude both copies of the page
            if page and page.publisher_public_id != instance.pk and page.pk != instance.pk:
                if create_links:
                    # Format return message with page url
                    url_clashes.append(
                        '<a href="%(page_url)s%(pk)s" target="_blank">%(page_title)s</a>'
                        % {
                            "page_url": reverse("admin:cms_page_changelist"),
                            "pk": page.pk,
                            "page_title": force_unicode(page),
                        }
                    )
                else:
                    # Just return the page name
                    url_clashes.append("'%s'" % page)
        if url_clashes:
            # If clashing pages exist raise the exception
            raise ValidationError(
                mark_safe(
                    ungettext_lazy(
                        "Page %(pages)s has the same url '%(url)s' as current page \"%(instance)s\".",
                        "Pages %(pages)s have the same url '%(url)s' as current page \"%(instance)s\".",
                        len(url_clashes),
                    )
                    % {"pages": ", ".join(url_clashes), "url": url, "instance": instance}
                )
            )
    return True
Exemplo n.º 8
0
def is_valid_url(url, instance, create_links=True, site=None):
    """ Checks for conflicting urls
    """
    page_root = urllib.unquote(reverse("pages-root"))
    if url and url != page_root:
        # Url sanity check via regexp
        if not any_path_re.match(url):
            raise ValidationError(_('Invalid URL, use /my/url format.'))
        # We only check page FK to site object to allow is_valid_url check on
        # incomplete Page instances
        if not site and instance.site_id:
            site = instance.site
        # Retrieve complete queryset of pages with corresponding URL
        # This uses the same resolving function as ``get_page_from_path``
        if url.startswith(page_root):
            url = url[len(page_root):]
        page_qs = get_page_queryset_from_path(url.strip('/'), site=site)
        url_clashes = []
        # If queryset has pages checks for conflicting urls
        if page_qs is not None:
            # If single page is returned create a list for interface compat
            if isinstance(page_qs, Page):
                page_qs = [page_qs]
            for page in page_qs:
                # Every page in the queryset except the current one is a conflicting page
                # We have to exclude both copies of the page
                if page and page.publisher_public.pk != instance.pk:
                    if create_links:
                        # Format return message with page url
                        url_clashes.append('<a href="%(page_url)s%(pk)s" target="_blank">%(page_title)s</a>' % {
                            'page_url': reverse('admin:cms_page_changelist'), 'pk': page.pk,
                            'page_title': force_unicode(page),
                        })
                    else:
                        # Just return the page name
                        url_clashes.append("'%s'" % page)
            if url_clashes:
                # If clashing pages exist raise the exception
                raise ValidationError(mark_safe(
                    ungettext_lazy('Page %(pages)s has the same url \'%(url)s\' as current page "%(instance)s".',
                                   'Pages %(pages)s have the same url \'%(url)s\' as current page "%(instance)s".',
                                    len(url_clashes)) %
                    {'pages': ', '.join(url_clashes), 'url': url, 'instance': instance}))
    return True
Exemplo n.º 9
0
def is_valid_url(url,instance,create_links=True):
    """ Checks for conflicting urls
    """
    if url:
        # Url sanity check via regexp
        if not any_path_re.match(url):
            raise ValidationError(_('Invalid URL, use /my/url format.'))
        # Retrieve complete queryset of pages with corresponding URL
        # This uses the same resolving function as ``get_page_from_path``
        page_qs = get_page_queryset_from_path(url.strip('/'))
        url_clashes = []
        # If queryset has pages checks for conflicting urls
        if page_qs is not None:
            # If single page is returned create a list for interface compat
            if isinstance(page_qs,Page):
                page_qs = [page_qs]
            for page in page_qs:
                # Every page in the queryset except the current one is a conflicting page
                # When CMS_MODERATOR is active we have to exclude both copies of the page
                if page and ((not settings.CMS_MODERATOR and page.pk != instance.pk) or
                             (settings.CMS_MODERATOR and page.publisher_public.pk != instance.pk)):
                    if create_links:
                        # Format return message with page url
                        url_clashes.append('<a href="%(page_url)s%(pk)s" target="_blank">%(page_title)s</a>' %
                                           {'page_url':reverse('admin:cms_page_changelist'),'pk':page.pk,
                                            'page_title': force_unicode(page)
                                            } )
                    else:
                        # Just return the page name
                        url_clashes.append("'%s'" % page)
            if url_clashes:
                # If clashing pages exist raise the exception
                raise ValidationError(mark_safe(ungettext_lazy('Page %(pages)s has the same url \'%(url)s\' as current page "%(instance)s".',
                                                     'Pages %(pages)s have the same url \'%(url)s\' as current page "%(instance)s".',
                                                    len(url_clashes)) %
                                      {'pages':", ".join(url_clashes),'url':url,'instance':instance}))
    return True
Exemplo n.º 10
0
 def clean_overwrite_url(self):
     url = self.cleaned_data['overwrite_url']
     if url:
         if not any_path_re.match(url):
             raise forms.ValidationError(ugettext_lazy('Invalid url, use /my/url format.'))
     return url