Mercurial > public > sg101
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/downloads/forms.py Mon Apr 06 02:43:12 2009 +0000 @@ -0,0 +1,45 @@ +""" +Forms for the downloads application. +""" +import os + +from django import forms + +from downloads.models import Download +from downloads.models import AllowedExtension + + +class SearchForm(forms.Form): + """Downloads search form.""" + text = forms.CharField(max_length=30) + + def query(self): + return self.cleaned_data['text'] + + +class AddDownloadForm(forms.ModelForm): + """Form to allow adding downloads.""" + + def clean_file(self): + file = self.cleaned_data['file'] + ext = os.path.splitext(file.name)[1] + allowed_exts = AllowedExtension.objects.get_extension_list() + if ext in allowed_exts: + return file + raise forms.ValidationError('The file extension "%s" is not allowed.' % ext) + + class Meta: + model = Download + fields = ('title', 'category', 'description', 'file') + + class Media: + css = { + 'all': ('js/markitup/skins/markitup/style.css', + 'js/markitup/sets/markdown/style.css') + } + js = ( + 'js/jquery-1.2.6.min.js', + 'js/downloads/add.js', + 'js/markitup/jquery.markitup.pack.js', + 'js/markitup/sets/markdown/set.js', + )