Mercurial > public > sg101
comparison gpp/downloads/forms.py @ 1:dbd703f7d63a
Initial import of sg101 stuff from private repository.
author | gremmie |
---|---|
date | Mon, 06 Apr 2009 02:43:12 +0000 |
parents | |
children | b6263ac72052 |
comparison
equal
deleted
inserted
replaced
0:900ba3c7b765 | 1:dbd703f7d63a |
---|---|
1 """ | |
2 Forms for the downloads application. | |
3 """ | |
4 import os | |
5 | |
6 from django import forms | |
7 | |
8 from downloads.models import Download | |
9 from downloads.models import AllowedExtension | |
10 | |
11 | |
12 class SearchForm(forms.Form): | |
13 """Downloads search form.""" | |
14 text = forms.CharField(max_length=30) | |
15 | |
16 def query(self): | |
17 return self.cleaned_data['text'] | |
18 | |
19 | |
20 class AddDownloadForm(forms.ModelForm): | |
21 """Form to allow adding downloads.""" | |
22 | |
23 def clean_file(self): | |
24 file = self.cleaned_data['file'] | |
25 ext = os.path.splitext(file.name)[1] | |
26 allowed_exts = AllowedExtension.objects.get_extension_list() | |
27 if ext in allowed_exts: | |
28 return file | |
29 raise forms.ValidationError('The file extension "%s" is not allowed.' % ext) | |
30 | |
31 class Meta: | |
32 model = Download | |
33 fields = ('title', 'category', 'description', 'file') | |
34 | |
35 class Media: | |
36 css = { | |
37 'all': ('js/markitup/skins/markitup/style.css', | |
38 'js/markitup/sets/markdown/style.css') | |
39 } | |
40 js = ( | |
41 'js/jquery-1.2.6.min.js', | |
42 'js/downloads/add.js', | |
43 'js/markitup/jquery.markitup.pack.js', | |
44 'js/markitup/sets/markdown/set.js', | |
45 ) |