Some changes that somehow got lost on my file system.
[redakcja.git] / apps / wiki / forms.py
1 # -*- coding: utf-8 -*-
2 #
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.
5 #
6 from django import forms
7 from wiki.constants import DOCUMENT_TAGS, DOCUMENT_STAGES
8 from django.utils.translation import ugettext_lazy as _
9
10
11 class DocumentTagForm(forms.Form):
12     """
13         Form for tagging revisions.
14     """
15
16     id = forms.CharField(widget=forms.HiddenInput)
17     tag = forms.ChoiceField(choices=DOCUMENT_TAGS)
18     revision = forms.IntegerField(widget=forms.HiddenInput)
19
20
21 class DocumentCreateForm(forms.Form):
22     """
23         Form used for creating new documents.
24     """
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)
29
30     def clean(self):
31         file = self.cleaned_data['file']
32
33         if file is not None:
34             try:
35                 self.cleaned_data['text'] = file.read().decode('utf-8')
36             except UnicodeDecodeError:
37                 raise forms.ValidationError("Text file must be UTF-8 encoded.")
38
39         if not self.cleaned_data["text"]:
40             raise forms.ValidationError("You must either enter text or upload a file")
41
42         return self.cleaned_data
43
44
45 class DocumentTextSaveForm(forms.Form):
46     """
47     Form for saving document's text:
48
49         * name - document's storage identifier.
50         * parent_revision - revision which the modified text originated from.
51         * comment - user's verbose comment; will be used in commit.
52         * stage_completed - mark this change as end of given stage.
53
54     """
55
56     id = forms.CharField(widget=forms.HiddenInput)
57     parent_revision = forms.IntegerField(widget=forms.HiddenInput)
58     text = forms.CharField(widget=forms.HiddenInput)
59
60     author = forms.CharField(
61         required=False,
62         label=_(u"Autor"),
63         help_text=_(u"Twoje imie i nazwisko lub email."),
64     )
65
66     comment = forms.CharField(
67         required=True,
68         widget=forms.Textarea,
69         label=_(u"Twój komentarz"),
70         help_text=_(u"Opisz w miarę dokładnie swoje zmiany."),
71     )
72
73     stage_completed = forms.ChoiceField(
74         choices=DOCUMENT_STAGES,
75         required=False,
76         label=_(u"Skończyłem robić"),
77         help_text=_(u"Jeśli skończyłeś jeden z etapów utworu, wybierz go."),
78     )