First draft image gallery
[sommitrealweird.git] / sommitrealweird / photo / context_processors.py
diff --git a/sommitrealweird/photo/context_processors.py b/sommitrealweird/photo/context_processors.py
new file mode 100644 (file)
index 0000000..b00e5e1
--- /dev/null
@@ -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 {}