Mercurial > public > sg101
annotate gpp/downloads/forms.py @ 133:c515b7401078
Use the new common way to apply markItUp to textareas and to get the smiley and markdown help dialogs for all the remaining apps except for forums and comments.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 27 Nov 2009 00:21:47 +0000 |
parents | f408971657b9 |
children | b4305e18d3af |
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 |
bgneal@6 | 7 from django.conf import settings |
gremmie@1 | 8 |
gremmie@1 | 9 from downloads.models import Download |
gremmie@1 | 10 from downloads.models import AllowedExtension |
gremmie@1 | 11 |
gremmie@1 | 12 |
gremmie@1 | 13 class SearchForm(forms.Form): |
gremmie@1 | 14 """Downloads search form.""" |
gremmie@1 | 15 text = forms.CharField(max_length=30) |
gremmie@1 | 16 |
gremmie@1 | 17 def query(self): |
gremmie@1 | 18 return self.cleaned_data['text'] |
gremmie@1 | 19 |
gremmie@1 | 20 |
gremmie@1 | 21 class AddDownloadForm(forms.ModelForm): |
gremmie@1 | 22 """Form to allow adding downloads.""" |
bgneal@133 | 23 title = forms.CharField(required=True, |
bgneal@133 | 24 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 64})) |
bgneal@133 | 25 description = forms.CharField(required=False, |
bgneal@133 | 26 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) |
gremmie@1 | 27 |
gremmie@1 | 28 def clean_file(self): |
gremmie@1 | 29 file = self.cleaned_data['file'] |
gremmie@1 | 30 ext = os.path.splitext(file.name)[1] |
gremmie@1 | 31 allowed_exts = AllowedExtension.objects.get_extension_list() |
gremmie@1 | 32 if ext in allowed_exts: |
gremmie@1 | 33 return file |
gremmie@1 | 34 raise forms.ValidationError('The file extension "%s" is not allowed.' % ext) |
gremmie@1 | 35 |
gremmie@1 | 36 class Meta: |
gremmie@1 | 37 model = Download |
gremmie@1 | 38 fields = ('title', 'category', 'description', 'file') |
gremmie@1 | 39 |
gremmie@1 | 40 class Media: |
gremmie@1 | 41 css = { |
bgneal@133 | 42 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + |
bgneal@133 | 43 settings.GPP_THIRD_PARTY_CSS['jquery-ui']) |
gremmie@1 | 44 } |
bgneal@133 | 45 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + |
bgneal@133 | 46 settings.GPP_THIRD_PARTY_JS['jquery-ui']) |