Ticket #12065: django-flatpages-url_clash.patch
File django-flatpages-url_clash.patch, 2.2 KB (added by , 15 years ago) |
---|
-
django/contrib/flatpages/admin.py
11 11 error_message = _("This value must contain only letters, numbers," 12 12 " underscores, dashes or slashes.")) 13 13 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 14 29 class Meta: 15 30 model = FlatPage 16 31 -
django/contrib/flatpages/views.py
1 1 from django.contrib.flatpages.models import FlatPage 2 2 from django.template import loader, RequestContext 3 from django.shortcuts import get_object_or_404 4 from django.http import HttpResponse, HttpResponseRedirect 3 from django.http import HttpResponse, HttpResponseRedirect, Http404 5 4 from django.conf import settings 6 5 from django.core.xheaders import populate_xheaders 7 6 from django.utils.safestring import mark_safe … … 23 22 return HttpResponseRedirect("%s/" % request.path) 24 23 if not url.startswith('/'): 25 24 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 27 29 # If registration is required for accessing this page, and the user isn't 28 30 # logged in, redirect to the login page. 29 31 if f.registration_required and not request.user.is_authenticated():