]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/blog/context_processors.py
e63a85f24b4e4f89cc4a360c8f60790016d730f0
[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 content_breadcrumb(request):
6     path = request.path
7     if path[0:len(settings.BLOG_ROOT)] == settings.BLOG_ROOT:
8         breadcrumb = [{'url': u'/', 'title': u'Home'}, {'url': settings.BLOG_ROOT, 'title': u'blog'},]
9
10         path = path[len(settings.BLOG_ROOT):]
11
12         parts = path.split('/')
13
14         if parts[0] == "section":
15             # Just need to add the section title to the breadcrumb
16             section = BlogSection.objects.get(slug__exact=parts[1])
17             breadcrumb.append({'url': section.get_absolute_url(), 'title': section.title})
18
19         if len(parts) == 5 and  \
20             parts[0].isdigit() and \
21             parts[1].isdigit() and \
22             parts[2].isdigit():
23                 # try getting the blog entry
24                 try:
25                     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])
26                     breadcrumb.append({'url': entry.get_absolute_url(), 'title': entry.title})
27                 except:
28                     breadcrumb.append({'url': 'nowhere', 'title': 'screwed'})
29                     pass
30
31         return {
32             'content_breadcrumb': breadcrumb,
33         }
34     else:
35         return {}