]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blobdiff - sommitrealweird/photo/views.py
Update for newer django
[sommitrealweird.git] / sommitrealweird / photo / views.py
index 28955abc072f3b32fa2a4880ef4976e92f308300..bddd15dac75772187c90841e3964e35f463294d0 100644 (file)
@@ -1,30 +1,37 @@
 from django.views.generic import ListView, DetailView
 from django.http import Http404
 from django.views.generic import ListView, DetailView
 from django.http import Http404
-from models import Album, Photo
+from photo.models import Album, Photo
 
 class AlbumListView(ListView):
     model = Album
     queryset = Album.objects.order_by('-name')
     paginate_by = 20
 
 
 class AlbumListView(ListView):
     model = Album
     queryset = Album.objects.order_by('-name')
     paginate_by = 20
 
-    def get_context_data(self, **kwargs):
-        context = super(AlbumListView, self).get_context_data(**kwargs)
-        return context
-
 class PhotoListView(ListView):
     model = Photo
     paginate_by = 20
 class PhotoListView(ListView):
     model = Photo
     paginate_by = 20
-    order_by = 'order, image'
+
+    def order_by(self):
+        return self.ordering
 
     def get_queryset(self):
 
     def get_queryset(self):
-        album = Album.objects.get(slug__exact=self.kwargs['slug'])
-        return Photo.objects.filter(album=album)
+        try:
+            album = Album.objects.get(slug__exact=self.kwargs['slug'])
+            return Photo.objects.filter(album=album).order_by('order', 'image')
+        except:
+            raise Http404
 
 class PhotoView(DetailView):
 
 class PhotoView(DetailView):
-    model = Photo
+
+    def get_queryset(self, **kwargs):
+        return Photo.objects.get(id=self.kwargs['id']).get_queryset()
 
     def get_object(self, **kwargs):
 
     def get_object(self, **kwargs):
-        return Photo.objects.get(id=self.kwargs['id'])
+        try:
+            photo = Photo.objects.get(id=self.kwargs['id'])
+            return photo
+        except:
+            raise Http404
 
     def get_context_data(self, **kwargs):
         context = super(PhotoView, self).get_context_data(**kwargs)
 
     def get_context_data(self, **kwargs):
         context = super(PhotoView, self).get_context_data(**kwargs)
@@ -52,4 +59,3 @@ class PhotoView(DetailView):
         context['prev_photo'] = prev_photo
 
         return context
         context['prev_photo'] = prev_photo
 
         return context
-