7ef02e150700d8ae3e42c7e0a16a93cac10d3159
[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 django.utils.translation import ugettext_lazy as _
8
9 from catalogue.constants import STAGES
10
11
12 class DocumentTextSaveForm(forms.Form):
13     """
14     Form for saving document's text:
15
16         * parent_revision - revision which the modified text originated from.
17         * comment - user's verbose comment; will be used in commit.
18         * stage - change to this stage
19
20     """
21
22     parent_revision = forms.IntegerField(widget=forms.HiddenInput, required=False)
23     text = forms.CharField(widget=forms.HiddenInput)
24
25     author_name = forms.CharField(
26         required=True,
27         label=_(u"Author"),
28         help_text=_(u"Your name"),
29     )
30
31     author_email = forms.EmailField(
32         required=True,
33         label=_(u"Author's email"),
34         help_text=_(u"Your email address, so we can show a gravatar :)"),
35     )
36
37     comment = forms.CharField(
38         required=False,
39         widget=forms.Textarea,
40         label=_(u"Your comments"),
41         help_text=_(u"Describe changes you made."),
42     )
43
44     stage = forms.ChoiceField(
45         choices=[(s, s) for s in STAGES],
46         required=False,
47         label=_(u"Stage"),
48         help_text=_(u"If completed a work stage, change to another one."),
49     )
50
51     def __init__(self, *args, **kwargs):
52         user = kwargs.pop('user')
53         super(DocumentTextSaveForm, self).__init__(*args, **kwargs)
54         if user and user.is_authenticated():
55             self.fields['author_name'].required = False
56             self.fields['author_email'].required = False
57
58
59 class DocumentTextRevertForm(forms.Form):
60     """
61     Form for reverting document's text:
62
63         * revision - revision to revert to.
64         * comment - user's verbose comment; will be used in commit.
65
66     """
67
68     revision = forms.IntegerField(widget=forms.HiddenInput)
69
70     author_name = forms.CharField(
71         required=False,
72         label=_(u"Author"),
73         help_text=_(u"Your name"),
74     )
75
76     author_email = forms.EmailField(
77         required=False,
78         label=_(u"Author's email"),
79         help_text=_(u"Your email address, so we can show a gravatar :)"),
80     )
81
82     comment = forms.CharField(
83         required=False,
84         widget=forms.Textarea,
85         label=_(u"Your comments"),
86         help_text=_(u"Describe the reason for reverting."),
87     )
88
89
90 class DocumentTextPublishForm(forms.Form):
91     revision = forms.IntegerField(widget=forms.HiddenInput)