From cd53e3ff1d5472af12a77de587b1df355cfb458d Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Fri, 27 Apr 2012 02:48:49 +0000 Subject: [PATCH] Correct typo in README, do basic form URL validation to make sure it is an image, the only thing Pinry currently supports. --- README.md | 2 +- pinry/pins/forms.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b808f5..b63a025 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ for bad code, I'll simply work with you to improve it. Have virtualenv and pip installed. You may also need to have the build dependencies for PIL installed. (If you are on Ubuntu you can do this by typing -"sudo build-dep python-imaging".) +"sudo apt-get build-dep python-imaging".) $ git clone git://github.com/overshard/pinry.git $ cd pinry diff --git a/pinry/pins/forms.py b/pinry/pins/forms.py index 6a4766a..21f929a 100644 --- a/pinry/pins/forms.py +++ b/pinry/pins/forms.py @@ -6,6 +6,14 @@ from .models import Pin class PinForm(forms.ModelForm): url = forms.CharField(label='URL') + 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 + class Meta: model = Pin exclude = ['image']