| 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 | |