Removed the global evil.
[redakcja.git] / apps / wiki / forms.py
1 from django import forms
2 from wiki.models import Document, getstorage
3
4
5 class DocumentForm(forms.Form):
6     name = forms.CharField(widget=forms.HiddenInput)
7     text = forms.CharField(widget=forms.Textarea)
8     revision = forms.IntegerField(widget=forms.HiddenInput)
9     comment = forms.CharField()
10     
11     def __init__(self, *args, **kwargs):
12         document = kwargs.pop('instance', None)
13         super(DocumentForm, self).__init__(*args, **kwargs)
14         if document:
15             self.fields['name'].initial = document.name
16             self.fields['text'].initial = document.text
17             self.fields['revision'].initial = document.revision()
18         
19     def save(self, document_author = 'anonymous'):
20         storage = getstorage()
21         
22         document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
23         
24         storage.put(document, 
25                 author = document_author, 
26                 comment = self.cleaned_data['comment'],
27                 parent =self.cleaned_data['revision'] )
28         
29         return storage.get(self.cleaned_data['name'])
30