# HG changeset patch # User Brian Neal # Date 1333834107 18000 # Node ID 4579bbb6e053d023a19354b4cad5fd5a24f1284d # Parent 0176eca97d1d9f612a3eb12c4e3c10a8fbeffa9c Cleaning up the band app's views. diff -r 0176eca97d1d -r 4579bbb6e053 madeira/band/urls.py --- 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'), ) diff -r 0176eca97d1d -r 4579bbb6e053 madeira/band/views.py --- 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)) + }) diff -r 0176eca97d1d -r 4579bbb6e053 madeira/templates/band/photos.html --- 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 %}

Random Photos:

- {% for photo in randomPhotos %} + {% for photo in random_photos %} {{ photo.caption }} {% endfor %}