Mercurial > public > sg101
annotate downloads/forms.py @ 1022:82f1f6f905eb
Perform image_check on private messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 09 Dec 2015 21:16:04 -0600 |
parents | 21c592cac71c |
children | a5ebc74dc3f3 |
rev | line source |
---|---|
gremmie@1 | 1 """ |
gremmie@1 | 2 Forms for the downloads application. |
gremmie@1 | 3 """ |
gremmie@1 | 4 import os |
gremmie@1 | 5 |
gremmie@1 | 6 from django import forms |
gremmie@1 | 7 |
bgneal@204 | 8 from downloads.models import PendingDownload |
gremmie@1 | 9 from downloads.models import AllowedExtension |
gremmie@1 | 10 |
gremmie@1 | 11 |
gremmie@1 | 12 class AddDownloadForm(forms.ModelForm): |
gremmie@1 | 13 """Form to allow adding downloads.""" |
bgneal@312 | 14 title = forms.CharField(required=True, |
bgneal@133 | 15 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 64})) |
bgneal@312 | 16 description = forms.CharField(required=False, |
bgneal@133 | 17 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) |
gremmie@1 | 18 |
gremmie@1 | 19 def clean_file(self): |
gremmie@1 | 20 file = self.cleaned_data['file'] |
gremmie@1 | 21 ext = os.path.splitext(file.name)[1] |
gremmie@1 | 22 allowed_exts = AllowedExtension.objects.get_extension_list() |
gremmie@1 | 23 if ext in allowed_exts: |
gremmie@1 | 24 return file |
gremmie@1 | 25 raise forms.ValidationError('The file extension "%s" is not allowed.' % ext) |
gremmie@1 | 26 |
gremmie@1 | 27 class Meta: |
bgneal@204 | 28 model = PendingDownload |
gremmie@1 | 29 fields = ('title', 'category', 'description', 'file') |