gremmie@1: """ gremmie@1: Forms for the downloads application. gremmie@1: """ gremmie@1: import os gremmie@1: gremmie@1: from django import forms bgneal@6: from django.conf import settings gremmie@1: gremmie@1: from downloads.models import Download gremmie@1: from downloads.models import AllowedExtension gremmie@1: gremmie@1: gremmie@1: class SearchForm(forms.Form): gremmie@1: """Downloads search form.""" gremmie@1: text = forms.CharField(max_length=30) gremmie@1: gremmie@1: def query(self): gremmie@1: return self.cleaned_data['text'] gremmie@1: gremmie@1: gremmie@1: class AddDownloadForm(forms.ModelForm): gremmie@1: """Form to allow adding downloads.""" gremmie@1: gremmie@1: def clean_file(self): gremmie@1: file = self.cleaned_data['file'] gremmie@1: ext = os.path.splitext(file.name)[1] gremmie@1: allowed_exts = AllowedExtension.objects.get_extension_list() gremmie@1: if ext in allowed_exts: gremmie@1: return file gremmie@1: raise forms.ValidationError('The file extension "%s" is not allowed.' % ext) gremmie@1: gremmie@1: class Meta: gremmie@1: model = Download gremmie@1: fields = ('title', 'category', 'description', 'file') gremmie@1: gremmie@1: class Media: gremmie@1: css = { bgneal@6: 'all': settings.GPP_THIRD_PARTY_CSS['markitup'], gremmie@1: } bgneal@12: js = settings.GPP_THIRD_PARTY_JS['markitup'] + \ bgneal@6: ('js/downloads/add.js', ) bgneal@6: