]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/bpcms/views.py
Update copyright years
[sommitrealweird.git] / sommitrealweird / bpcms / views.py
1 from bpcms.models import CSSDocument, Document, Folder
2 from django.http import Http404
3 from django.shortcuts import render
4 from django.template import RequestContext, loader
5
6 def document_view(request, slug=None, folders=None):
7     if folders == None and slug == None:
8         raise Http404()
9
10     folder = None
11
12     if folders != None:
13         folders = folders.split('/')
14         resfolder = None
15         for folder in folders:
16             try:
17                 if resfolder:
18                     resfolder = Folder.objects.get(slug__exact=folder, parent__exact=resfolder)
19                 else:
20                     resfolder = Folder.objects.get(slug__exact=folder, parent__isnull=True)
21                 resfolder = resfolder.id
22             except:
23                 raise Http404
24         try:
25             folder = Folder.objects.get(pk=resfolder)
26         except:
27             raise Http404
28
29     if folder != None:
30         try:
31             if not request.user.is_authenticated():
32                 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__exact=folder)
33             else:
34
35                 doc = Document.objects.get(slug__exact=slug, folder__exact=folder)
36         except:
37             try:
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)
41                 else:
42                     doc = Document.objects.get(slug__exact='index', folder__exact=folder)
43             except:
44                 raise Http404
45     else:
46         try:
47             if not request.user.is_authenticated():
48                 doc = Document.objects.get(slug__exact=slug, islive__exact=True, folder__isnull=True)
49             else:
50                 doc = Document.objects.get(slug__exact=slug, folder__isnull=True)
51         except:
52             try:
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)
56                 else:
57                     doc = Document.objects.get(slug__exact='index', folder__exact=folder)
58             except:
59                 raise Http404
60     template_name = "bpcms/%s.html" %(doc.format,)
61     c = {
62             "content"   : doc.content,
63             "title"     : doc.title,
64             "extracss"  : doc.extracss.all(),
65         }
66     return render(request, template_name, c)
67
68 def css_view(request, slug):
69     cssdoc = CSSDocument.objects.get(slug=slug)
70     if not cssdoc:
71         raise Http404()
72
73     return HttpResponse(cssdoc.content, content_type="text/css")
74