First draft image gallery
[sommitrealweird.git] / sommitrealweird / photo / views.py
1 import django.views.generic.list_detail
2 from django.http import Http404
3 from models import Album, Photo
4
5 def album_view(request, slug):
6     album = Album.objects.get(slug__exact=slug)
7     photos = Photo.objects.filter(album=album).order_by('order', 'image')
8     return django.views.generic.list_detail.object_list(request, photos, paginate_by=20, template_name='photo/photo_index.html')
9
10 def photo_view(request, slug, id):
11     id = int(id)
12     album = Album.objects.get(slug__exact=slug)
13     photos = Photo.objects.filter(album=album).order_by('order', 'image')
14     photo_qs = Photo.objects.filter(id=id)
15     found_prev = False
16     prev_photo = None
17     found_next = False
18     next_photo = None
19     for photo in photos:
20         if not found_prev:
21             if not photo.id == id:
22                 prev_photo = photo
23             else:
24                 found_prev = True
25         if found_next:
26             next_photo = photo
27             break
28         if photo.id == id:
29             found_next = True
30     return django.views.generic.list_detail.object_detail(request, photo_qs, object_id=id, template_name='photo/photo.html', extra_context={"next_photo": next_photo, "prev_photo": prev_photo })