Dodanie toolbara dla galerii
[redakcja.git] / apps / wiki / views.py
1 from django.views.generic.simple import direct_to_template
2 from django.http import HttpResponse, HttpResponseRedirect
3
4 from wiki.models import storage, Document, DocumentNotFound
5 from wiki.forms import DocumentForm
6
7
8 def document_list(request, template_name='wiki/document_list.html'):
9     return direct_to_template(request, template_name, extra_context={
10         'document_list': storage.all(),
11     })
12
13
14 def document_detail(request, name, template_name='wiki/document_details.html'):
15     try:
16         document = storage.get(name)
17     except DocumentNotFound:
18         document = Document(storage, name=name, text='')
19         
20     if request.method == 'POST':
21         form = DocumentForm(request.POST, instance=document)
22         if form.is_valid():
23             form.save()
24             return HttpResponse('OK')
25         else:
26             print form.errors
27     else:
28         form = DocumentForm(instance=document)
29     
30     return direct_to_template(request, template_name, extra_context={
31         'document': document,
32         'form': form,
33     })