1 # -*- coding: utf-8 -*-
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.
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 _
12 class DocumentForm(forms.Form):
13 """ Old form for saving document's text """
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()
20 def __init__(self, *args, **kwargs):
21 document = kwargs.pop('instance', None)
22 super(DocumentForm, self).__init__(*args, **kwargs)
24 self.fields['name'].initial = document.name
25 self.fields['text'].initial = document.text
26 self.fields['revision'].initial = document.revision()
28 def save(self, document_author='anonymous'):
29 storage = getstorage()
31 document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
34 author=document_author,
35 comment=self.cleaned_data['comment'],
36 parent=self.cleaned_data['revision'])
38 return storage.get(self.cleaned_data['name'])
41 class DocumentTagForm(forms.Form):
43 id = forms.CharField(widget=forms.HiddenInput)
44 tag = forms.ChoiceField(choices=DOCUMENT_TAGS)
45 revision = forms.IntegerField(widget=forms.HiddenInput)
48 class DocumentTextSaveForm(forms.Form):
50 Form for saving document's text:
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.
59 id = forms.CharField(widget=forms.HiddenInput)
60 parent_revision = forms.IntegerField(widget=forms.HiddenInput)
61 text = forms.CharField(widget=forms.HiddenInput)
63 author = forms.CharField(
66 help_text=_(u"Twoje imie i nazwisko lub email."),
69 comment = forms.CharField(
71 widget=forms.Textarea,
72 label=_(u"Twój komentarz"),
73 help_text=_(u"Opisz w miarę dokładnie swoje zmiany."),
76 stage_completed = forms.ChoiceField(
77 choices=DOCUMENT_STAGES,
79 label=_(u"Skończyłem robić"),
80 help_text=_(u"Jeśli skończyłeś jeden z etapów utworu, wybierz go."),