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
12 def document_list(request, template_name='wiki/document_list.html'):
13 return direct_to_template(request, template_name, extra_context={
14 'document_list': storage.all(),
18 def document_detail(request, name, template_name='wiki/document_details.html'):
20 document = storage.get(name)
21 except DocumentNotFound:
22 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)
45 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')]
46 return HttpResponse(json.dumps(images))
47 except (IndexError, OSError), e: