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: bgneal@204: from downloads.models import PendingDownload 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.""" bgneal@133: title = forms.CharField(required=True, bgneal@133: widget=forms.TextInput(attrs={'size': 64, 'maxlength': 64})) bgneal@133: description = forms.CharField(required=False, bgneal@133: widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) 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: bgneal@204: model = PendingDownload gremmie@1: fields = ('title', 'category', 'description', 'file') gremmie@1: gremmie@1: class Media: gremmie@1: css = { bgneal@133: 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] + bgneal@133: settings.GPP_THIRD_PARTY_CSS['jquery-ui']) gremmie@1: } bgneal@133: js = (settings.GPP_THIRD_PARTY_JS['markitup'] + bgneal@133: settings.GPP_THIRD_PARTY_JS['jquery-ui'])