X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/2e02e107aff23d09c81ac970101ebe2f9ce5e760..bb8272178c6c35fcb92bc5a08342faf40d3fab1b:/sommitrealweird/blog/context_processors.py?ds=sidebyside diff --git a/sommitrealweird/blog/context_processors.py b/sommitrealweird/blog/context_processors.py new file mode 100644 index 0000000..14a9216 --- /dev/null +++ b/sommitrealweird/blog/context_processors.py @@ -0,0 +1,35 @@ +from django.conf import settings +from blog.models import BlogEntry, BlogSection +import re + +def content_breadcrumb(request): + path = request.path + if path[0:len(settings.BLOG_ROOT)] == settings.BLOG_ROOT: + breadcrumb = [{'url': u'/', 'title': u'/'}, {'url': settings.BLOG_ROOT, 'title': u'blog'},] + + path = path[len(settings.BLOG_ROOT):] + + parts = path.split('/') + + if parts[0] == "section": + # Just need to add the section title to the breadcrumb + section = BlogSection.objects.get(slug__exact=parts[1]) + breadcrumb.append({'url': section.get_absolute_url(), 'title': section.title}) + + if len(parts) == 5 and \ + parts[0].isdigit() and \ + parts[1].isdigit() and \ + parts[2].isdigit(): + # try getting the blog entry + try: + 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]) + breadcrumb.append({'url': entry.get_absolute_url(), 'title': entry.title}) + except: + breadcrumb.append({'url': 'nowhere', 'title': 'screwed'}) + pass + + return { + 'content_breadcrumb': breadcrumb, + } + else: + return {}