changeset 56:4579bbb6e053

Cleaning up the band app's views.
author Brian Neal <bgneal@gmail.com>
date Sat, 07 Apr 2012 16:28:27 -0500
parents 0176eca97d1d
children 5ff9c130f47f
files madeira/band/urls.py madeira/band/views.py madeira/templates/band/photos.html
diffstat 3 files changed, 35 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/madeira/band/urls.py	Sat Apr 07 15:58:51 2012 -0500
+++ b/madeira/band/urls.py	Sat Apr 07 16:28:27 2012 -0500
@@ -1,9 +1,13 @@
+"""
+Urls for the band application.
+
+"""
 from django.conf.urls.defaults import patterns, url
 
 urlpatterns = patterns('band.views',
-   (r'^bio/$', 'bio'),
-   (r'^buy/$', 'buy'),
-   (r'^contact/$', 'contact'),
-   (r'^photos/$', 'photos_index'),
-   (r'^photos/(\d+)$', 'photo_detail'),
+   url(r'^bio/$', 'bio', name='band-bio'),
+   url(r'^buy/$', 'buy', name='band-buy'),
+   url(r'^contact/$', 'contact', name='band-contact'),
+   url(r'^photos/$', 'photos_index', name='band-photo_index'),
+   url(r'^photos/(\d+)$', 'photo_detail', name='band-photo_detail'),
 )
--- a/madeira/band/views.py	Sat Apr 07 15:58:51 2012 -0500
+++ b/madeira/band/views.py	Sat Apr 07 16:28:27 2012 -0500
@@ -4,65 +4,54 @@
 """
 import random
 
-from django.shortcuts import render_to_response
+from django.shortcuts import render
 from django.shortcuts import get_object_or_404
-from django.template import RequestContext
-
-from band.models import Member
-from band.models import Merchandise
 from photologue.models import Gallery
 from photologue.models import Photo
 
+from band.models import Member, Merchandise, Album
+
 
 def bio(request):
-    members = Member.objects.exclude(is_active__exact = 0)
-
-    return render_to_response('band/bio.html', 
-            { 'members' : members, },
-            context_instance = RequestContext(request))
+    members = Member.objects.exclude(is_active=0)
+    return render(request, 'band/bio.html', {'members': members})
 
 
 def photos_index(request):
     galleries = Gallery.objects.values('title', 'id').order_by('-id')
 
-    photos = Photo.objects.filter(is_public__exact = 1)
-    randomPhotos = random.sample(photos, 4)
+    photo_ids = Photo.objects.filter(is_public=True).values_list('id',
+            flat=True)
+    photo_ids = random.sample(photo_ids, 4)
+    random_photos = Photo.objects.filter(id__in=photo_ids)
 
-    return render_to_response('band/photos.html',
-            { 'galleries' : galleries, 'randomPhotos' : randomPhotos },
-            context_instance = RequestContext(request))
+    return render(request, 'band/photos.html', {
+        'galleries': galleries,
+        'random_photos': random_photos,
+    })
 
 
 def photo_detail(request, id):
-    gallery = get_object_or_404(Gallery, pk = id)
+    gallery = get_object_or_404(Gallery, pk=id)
     photos = gallery.photos.order_by('id')
-    return render_to_response('band/photo_detail.html',
-         {'gallery' : gallery, 'photos': photos },
-         context_instance = RequestContext(request))
+
+    return render(request, 'band/photo_detail.html', {
+        'gallery': gallery,
+        'photos': photos,
+    })
 
 
 def buy(request):
     albums = Album.objects.all().order_by('-id')
     merchandise = Merchandise.objects.all().order_by('-id')
-    return render_to_response('band/buy.html', { 
+    return render(request, 'band/buy.html', {
         'albums': albums, 
         'merchandise': merchandise, 
-        },
-        context_instance=RequestContext(request))
+    })
 
 
 def contact(request):
-    band = Member.objects.exclude(is_active__exact = 0).order_by('order')
-    return render_to_response('band/contact.html', {
+    band = Member.objects.exclude(is_active=0).order_by('order')
+    return render(request, 'band/contact.html', {
         'band': band,
-        },
-        context_instance=RequestContext(request))
-
-
-def flyers(request):
-
-    gigs = Gig.objects.exclude(flyer__isnull = True).order_by('-date')
-
-    return render_to_response('band/flyers.html',
-            { 'gigs' : gigs },
-            context_instance = RequestContext(request))
+    })
--- a/madeira/templates/band/photos.html	Sat Apr 07 15:58:51 2012 -0500
+++ b/madeira/templates/band/photos.html	Sat Apr 07 16:28:27 2012 -0500
@@ -24,10 +24,10 @@
 {% else %}
 No photo galleries available at this time.
 {% endif %}
-{% if randomPhotos %}
+{% if random_photos %}
    <div class="madeira-photo-list">
    <h2>Random Photos:</h2>
-   {% for photo in randomPhotos %}
+   {% for photo in random_photos %}
       <a href="{{ photo.image.url }}" class="fancybox" rel="madeira-gallery">
          <img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.caption }}" title="{{ photo.caption }}" /></a>
    {% endfor %}