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 wiki.models import Book
9 from django.utils.translation import ugettext_lazy as _
12 class DocumentTagForm(forms.Form):
14 Form for tagging revisions.
17 id = forms.CharField(widget=forms.HiddenInput)
18 tag = forms.ChoiceField(choices=DOCUMENT_TAGS)
19 revision = forms.IntegerField(widget=forms.HiddenInput)
22 class DocumentCreateForm(forms.ModelForm):
24 Form used for creating new documents.
26 file = forms.FileField(required=False)
27 text = forms.CharField(required=False, widget=forms.Textarea)
34 super(DocumentCreateForm, self).clean()
35 file = self.cleaned_data['file']
39 self.cleaned_data['text'] = file.read().decode('utf-8')
40 except UnicodeDecodeError:
41 raise forms.ValidationError("Text file must be UTF-8 encoded.")
43 if not self.cleaned_data["text"]:
44 raise forms.ValidationError("You must either enter text or upload a file")
46 return self.cleaned_data
49 class DocumentsUploadForm(forms.Form):
51 Form used for uploading new documents.
53 file = forms.FileField(required=True, label=_('ZIP file'))
56 file = self.cleaned_data['file']
60 z = self.cleaned_data['zip'] = zipfile.ZipFile(file)
61 except zipfile.BadZipfile:
62 raise forms.ValidationError("Should be a ZIP file.")
64 raise forms.ValidationError("ZIP file corrupt.")
66 return self.cleaned_data
69 class DocumentTextSaveForm(forms.Form):
71 Form for saving document's text:
73 * parent_revision - revision which the modified text originated from.
74 * comment - user's verbose comment; will be used in commit.
75 * stage_completed - mark this change as end of given stage.
79 parent_revision = forms.IntegerField(widget=forms.HiddenInput)
80 text = forms.CharField(widget=forms.HiddenInput)
82 author_name = forms.CharField(
85 help_text=_(u"Your name"),
88 author_email = forms.EmailField(
90 label=_(u"Author's email"),
91 help_text=_(u"Your email address, so we can show a gravatar :)"),
94 comment = forms.CharField(
96 widget=forms.Textarea,
97 label=_(u"Your comments"),
98 help_text=_(u"Describe changes you made."),
101 stage_completed = forms.ChoiceField(
102 choices=DOCUMENT_STAGES,
104 label=_(u"Completed"),
105 help_text=_(u"If you completed a life cycle stage, select it."),
109 class DocumentTextRevertForm(forms.Form):
111 Form for reverting document's text:
113 * revision - revision to revert to.
114 * comment - user's verbose comment; will be used in commit.
118 revision = forms.IntegerField(widget=forms.HiddenInput)
120 author_name = forms.CharField(
123 help_text=_(u"Your name"),
126 author_email = forms.EmailField(
128 label=_(u"Author's email"),
129 help_text=_(u"Your email address, so we can show a gravatar :)"),
132 comment = forms.CharField(
134 widget=forms.Textarea,
135 label=_(u"Your comments"),
136 help_text=_(u"Describe the reason for reverting."),