Hard linking of texts to catalogue.
[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 approving revisions.
13     """
14
15     id = forms.CharField(widget=forms.HiddenInput)
16     publishable = forms.BooleanField(required=False, initial=True,
17             label=_('Approved'))
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=_('Approve'),
62         help_text=_("Approve this revision.")
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             try:
72                 user.profile
73             except:
74                 pass
75             else:
76                 if user.profile.approve_by_default:
77                     self.fields['publishable'].initial = True
78
79         return r
80
81
82 class DocumentTextRevertForm(forms.Form):
83     """
84     Form for reverting document's text:
85
86         * revision - revision to revert to.
87         * comment - user's verbose comment; will be used in commit.
88
89     """
90
91     revision = forms.IntegerField(widget=forms.HiddenInput)
92
93     author_name = forms.CharField(
94         required=False,
95         label=_(u"Author"),
96         help_text=_(u"Your name"),
97     )
98
99     author_email = forms.EmailField(
100         required=False,
101         label=_(u"Author's email"),
102         help_text=_(u"Your email address, so we can show a gravatar :)"),
103     )
104
105     comment = forms.CharField(
106         required=True,
107         widget=forms.Textarea,
108         label=_(u"Your comments"),
109         help_text=_(u"Describe the reason for reverting."),
110     )