1 # -*- coding: utf-8 -*-
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.
6 from django import forms
7 from wiki.models import Document, getstorage
10 class DocumentForm(forms.Form):
11 name = forms.CharField(widget=forms.HiddenInput)
12 text = forms.CharField(widget=forms.Textarea)
13 revision = forms.IntegerField(widget=forms.HiddenInput)
14 comment = forms.CharField()
16 def __init__(self, *args, **kwargs):
17 document = kwargs.pop('instance', None)
18 super(DocumentForm, self).__init__(*args, **kwargs)
20 self.fields['name'].initial = document.name
21 self.fields['text'].initial = document.text
22 self.fields['revision'].initial = document.revision()
24 def save(self, document_author = 'anonymous'):
25 storage = getstorage()
27 document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
30 author = document_author,
31 comment = self.cleaned_data['comment'],
32 parent =self.cleaned_data['revision'] )
34 return storage.get(self.cleaned_data['name'])