Logging for staging, removed unused requirements.
[redakcja.git] / apps / wiki / forms.py
1 from django import forms
2 from wiki.models import Document, storage
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 get_storage(self):
20         return storage
21         
22     def save(self, document_author = 'anonymous'):
23         document = Document(self.get_storage(), name=self.cleaned_data['name'], text=self.cleaned_data['text'])
24         
25         storage.put(document, 
26                 author = document_author, 
27                 comment = self.cleaned_data['comment'],
28                 parent =self.cleaned_data['revision'] )
29         
30         return storage.get(self.cleaned_data['name'])
31