Added in duplicate URL detection fixing issue #13.

This commit is contained in:
Isaac Bythewood
2012-04-27 15:11:41 +00:00
parent 520e2725f2
commit ce95b7ef7f

View File

@@ -8,11 +8,15 @@ class PinForm(forms.ModelForm):
def clean_url(self):
data = self.cleaned_data['url']
image_file_types = ['png', 'gif', 'jpeg', 'jpg']
file_type = data.split('.')[-1]
if file_type.lower() not in image_file_types:
raise forms.ValidationError("Requested URL is not an image file. Only images are currently supported.")
return data
try:
Pin.objects.get(url=data)
raise forms.ValidationError("URL has already been pinned!")
except Pin.DoesNotExist:
image_file_types = ['png', 'gif', 'jpeg', 'jpg']
file_type = data.split('.')[-1]
if file_type.lower() not in image_file_types:
raise forms.ValidationError("Requested URL is not an image file. Only images are currently supported.")
return data
class Meta:
model = Pin