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
7 def document_view(request, path = None):
12 folders = path.split("/")
19 for i,folder_name in enumerate(folders):
22 resfolder = Folder.objects.get(slug__exact=folder_name, parent__exact=resfolder)
24 resfolder = Folder.objects.get(slug__exact=folder_name, parent__isnull=True)
25 resfolder = resfolder.id
32 folder = Folder.objects.get(pk=resfolder)
34 raise Http404("Badgers")
41 if not request.user.is_authenticated:
42 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
45 doc = Document.objects.get(slug__exact=slug, folder__exact=folder)
48 folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
49 if not request.user.is_authenticated():
50 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
52 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
54 raise Http404(folder + "/" + slug)
57 if not request.user.is_authenticated:
58 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
60 doc = Document.objects.get(slug__exact=slug, folder__isnull=True)
63 folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
64 if not request.user.is_authenticated():
65 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
67 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
70 template_name = "bpcms/%s.html" %(doc.format,)
72 "content" : doc.content,
74 "extracss" : doc.extracss.all(),
76 return render(request, template_name, c)
78 def css_view(request, slug):
79 cssdoc = CSSDocument.objects.get(slug=slug)
83 return HttpResponse(cssdoc.content, content_type="text/css")