mirror of
https://github.com/pinry/pinry.git
synced 2025-11-14 09:05:41 +01:00
20 lines
541 B
Python
20 lines
541 B
Python
from django import forms
|
|
|
|
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']
|