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, slug=None, folders=None):
8 if folders == None and slug == None:
14 folders = folders.split('/')
16 for folder in folders:
19 resfolder = Folder.objects.get(slug__exact=folder, parent__exact=resfolder)
21 resfolder = Folder.objects.get(slug__exact=folder, parent__isnull=True)
22 resfolder = resfolder.id
26 folder = Folder.objects.get(pk=resfolder)
32 if not request.user.is_authenticated:
33 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
36 doc = Document.objects.get(slug__exact=slug, folder__exact=folder)
39 folder = Folder.objects.get(slug__exact=slug, parent__exact=folder)
40 if not request.user.is_authenticated():
41 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
43 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
48 if not request.user.is_authenticated:
49 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
51 doc = Document.objects.get(slug__exact=slug, folder__isnull=True)
53 sys.stderr.write("Unexpected error:", sys.exc_info()[0])
55 folder = Folder.objects.get(slug__exact=slug, parent__isnull=True)
56 if not request.user.is_authenticated():
57 doc = Document.objects.get(slug__exact='index', islive__exact=True, folder__exact=folder)
59 doc = Document.objects.get(slug__exact='index', folder__exact=folder)
62 template_name = "bpcms/%s.html" %(doc.format,)
64 "content" : doc.content,
66 "extracss" : doc.extracss.all(),
68 return render(request, template_name, c)
70 def css_view(request, slug):
71 cssdoc = CSSDocument.objects.get(slug=slug)
75 return HttpResponse(cssdoc.content, content_type="text/css")