annotate 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
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
gremmie@1 8 from downloads.models import Download
gremmie@1 9 from downloads.models import AllowedExtension
gremmie@1 10
gremmie@1 11
gremmie@1 12 class SearchForm(forms.Form):
gremmie@1 13 """Downloads search form."""
gremmie@1 14 text = forms.CharField(max_length=30)
gremmie@1 15
gremmie@1 16 def query(self):
gremmie@1 17 return self.cleaned_data['text']
gremmie@1 18
gremmie@1 19
gremmie@1 20 class AddDownloadForm(forms.ModelForm):
gremmie@1 21 """Form to allow adding downloads."""
gremmie@1 22
gremmie@1 23 def clean_file(self):
gremmie@1 24 file = self.cleaned_data['file']
gremmie@1 25 ext = os.path.splitext(file.name)[1]
gremmie@1 26 allowed_exts = AllowedExtension.objects.get_extension_list()
gremmie@1 27 if ext in allowed_exts:
gremmie@1 28 return file
gremmie@1 29 raise forms.ValidationError('The file extension "%s" is not allowed.' % ext)
gremmie@1 30
gremmie@1 31 class Meta:
gremmie@1 32 model = Download
gremmie@1 33 fields = ('title', 'category', 'description', 'file')
gremmie@1 34
gremmie@1 35 class Media:
gremmie@1 36 css = {
gremmie@1 37 'all': ('js/markitup/skins/markitup/style.css',
gremmie@1 38 'js/markitup/sets/markdown/style.css')
gremmie@1 39 }
gremmie@1 40 js = (
gremmie@1 41 'js/jquery-1.2.6.min.js',
gremmie@1 42 'js/downloads/add.js',
gremmie@1 43 'js/markitup/jquery.markitup.pack.js',
gremmie@1 44 'js/markitup/sets/markdown/set.js',
gremmie@1 45 )