X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/8f0e18f498d6c07937c92d186bfa6b654a1afa14..12d6c8f9c5b3edfe3c86a0a3b3ca1adcec706668:/apps/wiki/forms.py diff --git a/apps/wiki/forms.py b/apps/wiki/forms.py index e0c69fdd..e48c5eae 100644 --- a/apps/wiki/forms.py +++ b/apps/wiki/forms.py @@ -23,7 +23,7 @@ class DocumentCreateForm(forms.Form): Form used for creating new documents. """ title = forms.CharField() - id = forms.RegexField(regex=ur"\w+") + id = forms.RegexField(regex=ur"^[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$") file = forms.FileField(required=False) text = forms.CharField(required=False, widget=forms.Textarea) @@ -42,6 +42,26 @@ class DocumentCreateForm(forms.Form): return self.cleaned_data +class DocumentsUploadForm(forms.Form): + """ + Form used for uploading new documents. + """ + file = forms.FileField(required=True, label=_('ZIP file')) + + def clean(self): + file = self.cleaned_data['file'] + + import zipfile + try: + z = self.cleaned_data['zip'] = zipfile.ZipFile(file) + except zipfile.BadZipfile: + raise forms.ValidationError("Should be a ZIP file.") + if z.testzip(): + raise forms.ValidationError("ZIP file corrupt.") + + return self.cleaned_data + + class DocumentTextSaveForm(forms.Form): """ Form for saving document's text: @@ -60,7 +80,7 @@ class DocumentTextSaveForm(forms.Form): author_name = forms.CharField( required=False, label=_(u"Author"), - help_text=_(u"Your name/"), + help_text=_(u"Your name"), ) author_email = forms.EmailField(