Priviliged users can now add tags. Also, some minor cleanups in JS.
[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.models import Document, getstorage
8 from wiki.constants import DOCUMENT_TAGS, DOCUMENT_STAGES
9 from django.utils.translation import ugettext_lazy as _
10
11
12 class DocumentForm(forms.Form):
13     """ Old form for saving document's text """
14
15     name = forms.CharField(widget=forms.HiddenInput)
16     text = forms.CharField(widget=forms.Textarea)
17     revision = forms.IntegerField(widget=forms.HiddenInput)
18     comment = forms.CharField()
19
20     def __init__(self, *args, **kwargs):
21         document = kwargs.pop('instance', None)
22         super(DocumentForm, self).__init__(*args, **kwargs)
23         if document:
24             self.fields['name'].initial = document.name
25             self.fields['text'].initial = document.text
26             self.fields['revision'].initial = document.revision()
27
28     def save(self, document_author='anonymous'):
29         storage = getstorage()
30
31         document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
32
33         storage.put(document,
34                 author=document_author,
35                 comment=self.cleaned_data['comment'],
36                 parent=self.cleaned_data['revision'])
37
38         return storage.get(self.cleaned_data['name'])
39
40
41 class DocumentTagForm(forms.Form):
42
43     id = forms.CharField(widget=forms.HiddenInput)
44     tag = forms.ChoiceField(choices=DOCUMENT_TAGS)
45     revision = forms.IntegerField(widget=forms.HiddenInput)
46
47
48 class DocumentTextSaveForm(forms.Form):
49     """
50     Form for saving document's text:
51
52         * name - document's storage identifier.
53         * parent_revision - revision which the modified text originated from.
54         * comment - user's verbose comment; will be used in commit.
55         * stage_completed - mark this change as end of given stage.
56
57     """
58
59     id = forms.CharField(widget=forms.HiddenInput)
60     parent_revision = forms.IntegerField(widget=forms.HiddenInput)
61     text = forms.CharField(widget=forms.HiddenInput)
62
63     author = forms.CharField(
64         required=False,
65         label=_(u"Autor"),
66         help_text=_(u"Twoje imie i nazwisko lub email."),
67     )
68
69     comment = forms.CharField(
70         required=True,
71         widget=forms.Textarea,
72         label=_(u"Twój komentarz"),
73         help_text=_(u"Opisz w miarę dokładnie swoje zmiany."),
74     )
75
76     stage_completed = forms.ChoiceField(
77         choices=DOCUMENT_STAGES,
78         required=False,
79         label=_(u"Skończyłem robić"),
80         help_text=_(u"Jeśli skończyłeś jeden z etapów utworu, wybierz go."),
81     )