1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django import forms
7 from wiki.constants import DOCUMENT_TAGS, DOCUMENT_STAGES
8 from django.utils.translation import ugettext_lazy as _
11 class DocumentTagForm(forms.Form):
13 Form for tagging revisions.
16 id = forms.CharField(widget=forms.HiddenInput)
17 tag = forms.ChoiceField(choices=DOCUMENT_TAGS)
18 revision = forms.IntegerField(widget=forms.HiddenInput)
21 class DocumentCreateForm(forms.Form):
23 Form used for creating new documents.
25 title = forms.CharField()
26 id = forms.RegexField(regex=ur"^[-\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$")
27 file = forms.FileField(required=False)
28 text = forms.CharField(required=False, widget=forms.Textarea)
31 file = self.cleaned_data['file']
35 self.cleaned_data['text'] = file.read().decode('utf-8')
36 except UnicodeDecodeError:
37 raise forms.ValidationError("Text file must be UTF-8 encoded.")
39 if not self.cleaned_data["text"]:
40 raise forms.ValidationError("You must either enter text or upload a file")
42 return self.cleaned_data
45 class DocumentsUploadForm(forms.Form):
47 Form used for uploading new documents.
49 file = forms.FileField(required=True, label=_('ZIP file'))
52 file = self.cleaned_data['file']
56 z = self.cleaned_data['zip'] = zipfile.ZipFile(file)
57 except zipfile.BadZipfile:
58 raise forms.ValidationError("Should be a ZIP file.")
60 raise forms.ValidationError("ZIP file corrupt.")
62 return self.cleaned_data
65 class DocumentTextSaveForm(forms.Form):
67 Form for saving document's text:
69 * name - document's storage identifier.
70 * parent_revision - revision which the modified text originated from.
71 * comment - user's verbose comment; will be used in commit.
72 * stage_completed - mark this change as end of given stage.
76 id = forms.CharField(widget=forms.HiddenInput)
77 parent_revision = forms.IntegerField(widget=forms.HiddenInput)
78 text = forms.CharField(widget=forms.HiddenInput)
80 author_name = forms.CharField(
83 help_text=_(u"Your name"),
86 author_email = forms.EmailField(
88 label=_(u"Author's email"),
89 help_text=_(u"Your email address, so we can show a gravatar :)"),
92 comment = forms.CharField(
94 widget=forms.Textarea,
95 label=_(u"Your comments"),
96 help_text=_(u"Describe changes you made."),