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