Show Thema in legimi button
[redakcja.git] / src / wiki / forms.py
1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django import forms
5 from django.utils.translation import gettext_lazy as _
6
7 from documents.models import Chunk
8
9
10 class DocumentPubmarkForm(forms.Form):
11     """
12         Form for marking revisions for publishing.
13     """
14
15     id = forms.CharField(widget=forms.HiddenInput)
16     publishable = forms.BooleanField(required=False, initial=True,
17             label=_('Publishable'))
18     revision = forms.IntegerField(widget=forms.HiddenInput)
19
20
21 class DocumentTextSaveForm(forms.Form):
22     """
23     Form for saving document's text:
24
25         * parent_revision - revision which the modified text originated from.
26         * comment - user's verbose comment; will be used in commit.
27         * stage_completed - mark this change as end of given stage.
28
29     """
30
31     parent_revision = forms.IntegerField(widget=forms.HiddenInput, required=False)
32     text = forms.CharField(widget=forms.HiddenInput)
33
34     author_name = forms.CharField(
35         required=True,
36         label=_(u"Author"),
37         help_text=_(u"Your name"),
38     )
39
40     author_email = forms.EmailField(
41         required=True,
42         label=_(u"Author's email"),
43         help_text=_(u"Your email address, so we can show a gravatar :)"),
44     )
45
46     comment = forms.CharField(
47         required=True,
48         widget=forms.Textarea,
49         label=_(u"Your comments"),
50         help_text=_(u"Describe changes you made."),
51     )
52
53     stage_completed = forms.ModelChoiceField(
54         queryset=Chunk.tag_model.objects.all(),
55         required=False,
56         label=_(u"Completed"),
57         help_text=_(u"If you completed a life cycle stage, select it."),
58     )
59
60     publishable = forms.BooleanField(required=False, initial=False,
61         label=_('Publishable'),
62         help_text=_(u"Mark this revision as publishable.")
63     )
64
65     def __init__(self, *args, **kwargs):
66         user = kwargs.pop('user')
67         r = super(DocumentTextSaveForm, self).__init__(*args, **kwargs)
68         if user and user.is_authenticated:
69             self.fields['author_name'].required = False
70             self.fields['author_email'].required = False
71         return r
72
73
74 class DocumentTextRevertForm(forms.Form):
75     """
76     Form for reverting document's text:
77
78         * revision - revision to revert to.
79         * comment - user's verbose comment; will be used in commit.
80
81     """
82
83     revision = forms.IntegerField(widget=forms.HiddenInput)
84
85     author_name = forms.CharField(
86         required=False,
87         label=_(u"Author"),
88         help_text=_(u"Your name"),
89     )
90
91     author_email = forms.EmailField(
92         required=False,
93         label=_(u"Author's email"),
94         help_text=_(u"Your email address, so we can show a gravatar :)"),
95     )
96
97     comment = forms.CharField(
98         required=True,
99         widget=forms.Textarea,
100         label=_(u"Your comments"),
101         help_text=_(u"Describe the reason for reverting."),
102     )