3 from django.conf import settings
4 from django.views.generic.simple import direct_to_template
5 from django.http import HttpResponse, Http404
6 from django.utils import simplejson as json
8 from wiki.models import storage, Document, DocumentNotFound
9 from wiki.forms import DocumentForm
11 def document_list(request, template_name = 'wiki/document_list.html'):
12 return direct_to_template(request, template_name, extra_context = {
13 'document_list': storage.all(),
17 def document_detail(request, name, template_name = 'wiki/document_details.html'):
19 document = storage.get(name)
20 except DocumentNotFound:
23 # document = Document(storage, name = name, text = '')
25 if request.method == 'POST':
26 form = DocumentForm(request.POST, instance = document)
28 document = form.save()
29 return HttpResponse(json.dumps({'text': document.plain_text(), 'meta': document.meta(), 'revision': document.revision()}))
31 return HttpResponse(json.dumps({'errors': form.errors}))
33 form = DocumentForm(instance = document)
35 return direct_to_template(request, template_name, extra_context = {
41 def document_gallery(request, directory):
43 base_dir = os.path.join(settings.MEDIA_ROOT, settings.FILEBROWSER_DIRECTORY, directory)
44 images = [u'%s%s%s/%s' % (settings.MEDIA_URL, settings.FILEBROWSER_DIRECTORY, directory, f) for f in os.listdir(base_dir) if os.path.splitext(f)[1].lower() in (u'.jpg', u'.jpeg', u'.png')]
46 return HttpResponse(json.dumps(images))
47 except (IndexError, OSError), exc: