1 from content.models import Document, Folder
2 from django.http import Http404, HttpResponse
3 from django.template import RequestContext, loader
4 from settings import MEDIA_URL
6 def document_view(request, slug=None, folders=None):
7 if folders == None and slug == None:
13 folders = folders.split('/')
15 for folder in folders:
18 resfolder = Folder.objects.get(slug__exact=folder, parent__exact=resfolder)
20 resfolder = Folder.objects.get(slug__exact=folder, parent__isnull=True)
21 resfolder = resfolder.id
25 folder = Folder.objects.get(pk=resfolder)
31 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
34 folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
35 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
40 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
43 folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
44 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
47 template_name = "%s.html" %(doc.format,)
48 t = loader.get_template(template_name)
49 c = RequestContext(request,
51 "content" : doc.content,
53 "media_url" : MEDIA_URL,
55 return HttpResponse(t.render(c))