1 from bpcms.models import Document, Folder
2 from django.http import Http404, HttpResponse
3 from django.template import RequestContext, loader
5 def document_view(request, slug=None, folders=None):
6 if folders == None and slug == None:
12 folders = folders.split('/')
14 for folder in folders:
17 resfolder = Folder.objects.get(slug__exact=folder, parent__exact=resfolder)
19 resfolder = Folder.objects.get(slug__exact=folder, parent__isnull=True)
20 resfolder = resfolder.id
24 folder = Folder.objects.get(pk=resfolder)
30 if not request.user.is_authenticated():
31 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
34 doc = Document.objects.get(slug__exact=slug, folder__exact=folder)
37 folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
38 if not request.user.isauthenticated():
39 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
41 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
46 if not request.user.is_authenticated():
47 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
49 doc = Document.objects.get(slug__exact=slug, folder__isnull=True)
52 folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
53 if not request.user.is_authenticated():
54 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
56 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
59 template_name = "bpcms/%s.html" %(doc.format,)
60 t = loader.get_template(template_name)
61 c = RequestContext(request,
63 "content" : doc.content,
66 return HttpResponse(t.render(c))