comparison downloads/forms.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/downloads/forms.py@88b2b9cb8c1f
children 21c592cac71c
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 Forms for the downloads application.
3 """
4 import os
5
6 from django import forms
7 from django.conf import settings
8
9 from downloads.models import PendingDownload
10 from downloads.models import AllowedExtension
11
12
13 class AddDownloadForm(forms.ModelForm):
14 """Form to allow adding downloads."""
15 title = forms.CharField(required=True,
16 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 64}))
17 description = forms.CharField(required=False,
18 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'}))
19
20 def clean_file(self):
21 file = self.cleaned_data['file']
22 ext = os.path.splitext(file.name)[1]
23 allowed_exts = AllowedExtension.objects.get_extension_list()
24 if ext in allowed_exts:
25 return file
26 raise forms.ValidationError('The file extension "%s" is not allowed.' % ext)
27
28 class Meta:
29 model = PendingDownload
30 fields = ('title', 'category', 'description', 'file')
31
32 class Media:
33 css = {
34 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] +
35 settings.GPP_THIRD_PARTY_CSS['jquery-ui'])
36 }
37 js = (settings.GPP_THIRD_PARTY_JS['markitup'] +
38 settings.GPP_THIRD_PARTY_JS['jquery-ui'])