]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/photo/views.py
Initial port to django-1.7
[sommitrealweird.git] / sommitrealweird / photo / views.py
1 from django.views.generic import ListView
2 from django.http import Http404
3 from models import Album, Photo
4
5 class AlbumListView(ListView):
6     model = Album
7     queryset = Album.objects.order_by('-name')
8     paginate_by = 20
9
10     def get_context_data(self, **kwargs):
11         context = super(AlbumListView, self).get_context_data(**kwargs)
12         return context
13
14 def album_view(request, slug):
15     try:
16         album = Album.objects.get(slug__exact=slug)
17         photos = Photo.objects.filter(album=album).order_by('order', 'image')
18     except:
19         raise Http404
20     return django.views.generic.list_detail.object_list(request, photos, paginate_by=20, template_name='photo/photo_index.html', allow_empty=False)
21
22 def photo_view(request, slug, id):
23     try:
24         id = int(id)
25         album = Album.objects.get(slug__exact=slug)
26         photos = Photo.objects.filter(album=album).order_by('order', 'image')
27         photo_qs = Photo.objects.filter(id=id)
28         found_prev = False
29         prev_photo = None
30         found_next = False
31         next_photo = None
32         for photo in photos:
33             if not found_prev:
34                 if not photo.id == id:
35                     prev_photo = photo
36                 else:
37                     found_prev = True
38             if found_next:
39                 next_photo = photo
40                 break
41             if photo.id == id:
42                 found_next = True
43     except:
44         raise Http404
45     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 })