1 from bpcms.models import CSSDocument, Document, Folder
2 from django.http import Http404, HttpResponse
3 from django.shortcuts import render
4 from django.template import RequestContext, loader
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 if not request.user.is_authenticated():
32 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
35 doc = Document.objects.get(slug__exact=slug, folder__exact=folder)
38 folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
39 if not request.user.is_authenticated():
40 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
42 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
47 if not request.user.is_authenticated():
48 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
50 doc = Document.objects.get(slug__exact=slug, folder__isnull=True)
53 folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
54 if not request.user.is_authenticated():
55 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
57 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
60 template_name = "bpcms/%s.html" %(doc.format,)
62 "content" : doc.content,
64 "extracss" : doc.extracss.all(),
66 return render(request, template_name, c)
68 def css_view(request, slug):
69 cssdoc = CSSDocument.objects.get(slug=slug)
73 return HttpResponse(cssdoc.content, content_type="text/css")