]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/photo/context_processors.py
Fix copyright years
[sommitrealweird.git] / sommitrealweird / photo / context_processors.py
1 from django.conf import settings
2 from models import Album, Photo
3 import re
4
5 def content_breadcrumb(request):
6     path = request.path
7     if path[0:6] == "/photo":
8         breadcrumb = [{'url': u'/', 'title': u'Home'}, {'url': u'/photo/', 'title': u'Photos'}]
9         try:
10             path = path[7:]
11             album_slug = path.split('/', 1)[0]
12             album = Album.objects.get(slug__exact=album_slug)
13             breadcrumb.append({'url': u'/photo/%s/' %(album_slug), 'title': album.name})
14             try:
15                 rest = path.split('/', 1)[1]
16                 if len(rest) > 0:
17                     photo_id = rest.split('/')[0]
18                     photo_id = int(photo_id)
19                     photo = Photo.objects.get(id=photo_id)
20                     breadcrumb.append({'url': request.path, 'title': photo.image.name.split('/')[-1]})
21             except:
22                 pass
23         except:
24             pass
25
26         return {
27             'content_breadcrumb': breadcrumb,
28         }
29     else:
30         return {}