1 from django import forms
2 from wiki.models import Document, storage
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 get_storage(self):
22 def save(self, document_author = 'anonymous'):
23 document = Document(self.get_storage(), name=self.cleaned_data['name'], text=self.cleaned_data['text'])
26 author = document_author,
27 comment = self.cleaned_data['comment'],
28 parent =self.cleaned_data['revision'] )
30 return storage.get(self.cleaned_data['name'])