1 from django.views.generic.simple import direct_to_template
2 from django.http import HttpResponse
3 from django.utils import simplejson as json
5 from wiki.models import storage, Document, DocumentNotFound
6 from wiki.forms import DocumentForm
9 def document_list(request, template_name='wiki/document_list.html'):
10 return direct_to_template(request, template_name, extra_context={
11 'document_list': storage.all(),
15 def document_detail(request, name, template_name='wiki/document_details.html'):
17 document = storage.get(name)
18 except DocumentNotFound:
19 document = Document(storage, name=name, text='')
22 if request.method == 'POST':
23 form = DocumentForm(request.POST, instance=document)
25 document = form.save()
26 return HttpResponse(json.dumps({'text': document.plain_text(), 'meta': document.meta(), 'revision': document.revision()}))
28 return HttpResponse(json.dumps({'errors': form.errors}))
30 form = DocumentForm(instance=document)
32 return direct_to_template(request, template_name, extra_context={