]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/blog/context_processors.py
9c203cfcf3103103159eace676a744493c2e9603
[sommitrealweird.git] / sommitrealweird / blog / context_processors.py
1 from django.conf import settings
2 from blog.models import BlogEntry, BlogSection
3 import re
4
5 def blog_feed(request):
6     return {
7         'BLOG_FEED_ROOT': settings.BLOG_FEED_ROOT,
8     } 
9
10 def content_breadcrumb(request):
11     path = request.path
12     if path[0:len(settings.BLOG_ROOT)] == settings.BLOG_ROOT:
13         breadcrumb = [{'url': u'/', 'title': u'Home'}, {'url': settings.BLOG_ROOT, 'title': u'Blog'},]
14
15         path = path[len(settings.BLOG_ROOT):]
16
17         parts = path.split('/')
18
19         if parts[0] == "section":
20             # Just need to add the section title to the breadcrumb
21             section = BlogSection.objects.get(slug__exact=parts[1])
22             breadcrumb.append({'url': section.get_absolute_url(), 'title': section.title})
23
24         if len(parts) == 5 and  \
25             parts[0].isdigit() and \
26             parts[1].isdigit() and \
27             parts[2].isdigit():
28                 # try getting the blog entry
29                 try:
30                     entry = BlogEntry.objects.get(publish_date__year=int(parts[0]), publish_date__month=int(parts[1]), publish_date__day=int(parts[2]), slug__exact=parts[3])
31                     breadcrumb.append({'url': entry.get_absolute_url(), 'title': entry.title})
32                 except:
33                     breadcrumb.append({'url': 'nowhere', 'title': 'screwed'})
34                     pass
35
36         return {
37             'content_breadcrumb': breadcrumb,
38         }
39     else:
40         return {}