summaryrefslogtreecommitdiff
path: root/app/birds/views.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2015-11-08 19:54:58 -0500
committerluxagraf <sng@luxagraf.net>2015-11-08 19:54:58 -0500
commit76c0bf31bf4a21fcf18df8579dbb6f660c4d7437 (patch)
tree1088521913633ee867c62614b70ca0955302592e /app/birds/views.py
parenta1122250e52d8773fb672ac60a458e4b7d6570fb (diff)
Ported Bird app to CBV and modern URL structure. Also added base class
to utils module to handle my pagination scheme so I can reuse that bit of code
Diffstat (limited to 'app/birds/views.py')
-rw-r--r--app/birds/views.py58
1 files changed, 37 insertions, 21 deletions
diff --git a/app/birds/views.py b/app/birds/views.py
index bd2f79e..ea789fc 100644
--- a/app/birds/views.py
+++ b/app/birds/views.py
@@ -1,27 +1,43 @@
-from django.shortcuts import render_to_response, get_object_or_404
-from django.template import RequestContext
-from django.http import Http404
-from django.conf import settings
-# from django.views.generic import ListView
-
+from django.views.generic.detail import DetailView
+from django.contrib.auth.models import User
+from utils.views import PaginatedListView
from birds.models import Bird, BirdAudio, BirdSighting
-from locations.models import Region, Country
-def bird_list(request, user):
- #request.page_url = '/birds/seen/%d/'
- #request.page = int(page)
- context = {
- 'object_list': BirdSighting.objects.filter(seen_by__username=user),
- 'user': user,
- }
- return render_to_response("archives/birds.html", context, context_instance=RequestContext(request))
+class BirdListView(PaginatedListView):
+ template_name = 'archives/birds.html'
+
+ def get_queryset(self):
+ return BirdSighting.objects.all()
+
+
+class BirdListUserView(PaginatedListView):
+ template_name = 'archives/birds.html'
+
+ def get_queryset(self):
+ return BirdSighting.objects.filter(
+ seen_by__username=self.kwargs['user']
+ )
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(BirdListUserView, self).get_context_data(**kwargs)
+ context['user'] = User.objects.get(username=self.kwargs['user'])
+ return context
-def bird_detail(request, slug):
- context = {
- 'object': Bird.objects.get(slug=slug),
- 'recording': BirdAudio.objects.get(bird__slug=slug)
- }
- return render_to_response("details/bird.html", context, context_instance=RequestContext(request))
+class BirdDetailView(DetailView):
+ model = Bird
+ template_name = "details/bird.html"
+ slug_field = "slug"
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(BirdDetailView, self).get_context_data(**kwargs)
+ try:
+ context['recording'] = BirdAudio.objects.get(
+ bird__slug=self.kwargs['slug']
+ )
+ except BirdAudio.DoesNotExist:
+ return context
+ return context