1 from django import forms
2 from wiki.models import Document, getstorage
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()
11 def __init__(self, *args, **kwargs):
12 document = kwargs.pop('instance', None)
13 super(DocumentForm, self).__init__(*args, **kwargs)
15 self.fields['name'].initial = document.name
16 self.fields['text'].initial = document.text
17 self.fields['revision'].initial = document.revision()
19 def save(self, document_author = 'anonymous'):
20 storage = getstorage()
22 document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
25 author = document_author,
26 comment = self.cleaned_data['comment'],
27 parent =self.cleaned_data['revision'] )
29 return storage.get(self.cleaned_data['name'])