X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/1487722766c9e649c95a6f25ae29b0680bdc1be0..d82db041f520a51eccee6788ebc3a494e2a4280f:/sommitrealweird/photo/context_processors.py diff --git a/sommitrealweird/photo/context_processors.py b/sommitrealweird/photo/context_processors.py new file mode 100644 index 0000000..b00e5e1 --- /dev/null +++ b/sommitrealweird/photo/context_processors.py @@ -0,0 +1,30 @@ +from django.conf import settings +from models import Album, Photo +import re + +def content_breadcrumb(request): + path = request.path + if path[0:6] == "/photo": + breadcrumb = [{'url': u'/', 'title': u'Home'}, {'url': u'/photo/', 'title': u'Photos'}] + try: + path = path[7:] + album_slug = path.split('/', 1)[0] + album = Album.objects.get(slug__exact=album_slug) + breadcrumb.append({'url': u'/photo/%s/' %(album_slug), 'title': album.name}) + try: + rest = path.split('/', 1)[1] + if len(rest) > 0: + photo_id = rest.split('/')[0] + photo_id = int(photo_id) + photo = Photo.objects.get(id=photo_id) + breadcrumb.append({'url': request.path, 'title': photo.image.name.split('/')[-1]}) + except: + pass + except: + pass + + return { + 'content_breadcrumb': breadcrumb, + } + else: + return {}