02d80e67be0435a7dd04554ac6f9cc5b5b7be9f6
[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     try:
7         album = Album.objects.get(slug__exact=slug)
8         photos = Photo.objects.filter(album=album).order_by('order', 'image')
9     except:
10         raise Http404
11     return django.views.generic.list_detail.object_list(request, photos, paginate_by=20, template_name='photo/photo_index.html', allow_empty=False)
12
13 def photo_view(request, slug, id):
14     try:
15         id = int(id)
16         album = Album.objects.get(slug__exact=slug)
17         photos = Photo.objects.filter(album=album).order_by('order', 'image')
18         photo_qs = Photo.objects.filter(id=id)
19         found_prev = False
20         prev_photo = None
21         found_next = False
22         next_photo = None
23         for photo in photos:
24             if not found_prev:
25                 if not photo.id == id:
26                     prev_photo = photo
27                 else:
28                     found_prev = True
29             if found_next:
30                 next_photo = photo
31                 break
32             if photo.id == id:
33                 found_next = True
34     except:
35         raise Http404
36     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 })