From ce95b7ef7f7008e7889832cf7b4aad59ea5f6920 Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Fri, 27 Apr 2012 15:11:41 +0000 Subject: [PATCH] Added in duplicate URL detection fixing issue #13. --- pinry/pins/forms.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pinry/pins/forms.py b/pinry/pins/forms.py index 21f929a..c3175fd 100644 --- a/pinry/pins/forms.py +++ b/pinry/pins/forms.py @@ -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