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