Ticket #12065: admin.patch

File admin.patch, 1.0 KB (added by ryazwinski, 5 years ago)

patch to admin only to disallow url collisions - view continues to throw exception

  • 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
Back to Top