- return self.cleaned_data['download_url'] or None
-
- def clean_source_url(self):
- return self.cleaned_data['source_url'] or None
+ cl = self.cleaned_data['download_url'] or None
+ if cl is not None:
+ try:
+ img = Image.objects.get(download_url=cl)
+ except Image.DoesNotExist:
+ pass
+ else:
+ raise forms.ValidationError(mark_safe(
+ ugettext('Image <a href="%(url)s">already in repository</a>.'
+ ) % {'url': img.get_absolute_url()}))
+ return cl