gremmie@1: """ gremmie@1: Forms for the downloads application. gremmie@1: """ gremmie@1: import os gremmie@1: gremmie@1: from django import forms gremmie@1: bgneal@204: from downloads.models import PendingDownload gremmie@1: from downloads.models import AllowedExtension gremmie@1: gremmie@1: gremmie@1: class AddDownloadForm(forms.ModelForm): gremmie@1: """Form to allow adding downloads.""" bgneal@312: title = forms.CharField(required=True, bgneal@133: widget=forms.TextInput(attrs={'size': 64, 'maxlength': 64})) bgneal@312: 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')