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:
21 document = Document(storage, name = name, text = '')
24 if request.method == 'POST':
25 form = DocumentForm(request.POST, instance = document)
27 document = form.save()
28 return HttpResponse(json.dumps({'text': document.plain_text(), 'meta': document.meta(), 'revision': document.revision()}))
30 return HttpResponse(json.dumps({'errors': form.errors}))
32 form = DocumentForm(instance = document)
34 return direct_to_template(request, template_name, extra_context = {
40 def document_gallery(request, directory):
42 base_dir = os.path.join(settings.MEDIA_ROOT, settings.FILEBROWSER_DIRECTORY, directory)
43 images = ['%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 ('.jpg', '.jpeg', '.png')]
45 return HttpResponse(json.dumps(images))
46 except (IndexError, OSError), e: