Ticket #12065: django-flatpages-url_clash.patch

File django-flatpages-url_clash.patch, 2.2 KB (added by Michał Sałaban, 15 years ago)
  • django/contrib/flatpages/admin.py

     
    1111        error_message = _("This value must contain only letters, numbers,"
    1212                          " underscores, dashes or slashes."))
    1313
     14    def clean_sites(self):
     15        sites = self.cleaned_data['sites']
     16        url = self.cleaned_data['url']
     17        errors = []
     18        url_clash_query = FlatPage.objects.filter(url=url)
     19        if self.instance.pk:
     20            url_clash_query = url_clash_query.exclude(pk=self.instance.pk)
     21        for site in sites:
     22            clashes = url_clash_query.filter(sites=site)
     23            for clash in clashes:
     24                errors.append(_("There is already a page with the same url for site %s.") % site)
     25        if errors:
     26            raise forms.ValidationError, errors
     27        return sites
     28
    1429    class Meta:
    1530        model = FlatPage
    1631
  • django/contrib/flatpages/views.py

     
    11from django.contrib.flatpages.models import FlatPage
    22from django.template import loader, RequestContext
    3 from django.shortcuts import get_object_or_404
    4 from django.http import HttpResponse, HttpResponseRedirect
     3from django.http import HttpResponse, HttpResponseRedirect, Http404
    54from django.conf import settings
    65from django.core.xheaders import populate_xheaders
    76from django.utils.safestring import mark_safe
     
    2322        return HttpResponseRedirect("%s/" % request.path)
    2423    if not url.startswith('/'):
    2524        url = "/" + url
    26     f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
     25    try:
     26        f = FlatPage.objects.filter(url__exact=url, sites__id__exact=settings.SITE_ID)[0]
     27    except IndexError:
     28        raise Http404
    2729    # If registration is required for accessing this page, and the user isn't
    2830    # logged in, redirect to the login page.
    2931    if f.registration_required and not request.user.is_authenticated():
Back to Top