annotate band/views.py @ 131:9c74cd8668eb

For Django 1.6: take advantage of new database connection persistence.
author Brian Neal <bgneal@gmail.com>
date Tue, 24 Dec 2013 16:50:13 -0600
parents e2868ad47a1e
children 2db040e89285
rev   line source
bgneal@43 1 """
bgneal@43 2 Views for the band application.
bgneal@43 3
bgneal@43 4 """
bgneal@28 5 import random
bgneal@28 6
bgneal@56 7 from django.shortcuts import render
bgneal@1 8 from django.shortcuts import get_object_or_404
bgneal@40 9 from photologue.models import Gallery
bgneal@40 10 from photologue.models import Photo
bgneal@1 11
bgneal@56 12 from band.models import Member, Merchandise, Album
bgneal@56 13
bgneal@43 14
bgneal@43 15 def bio(request):
bgneal@56 16 members = Member.objects.exclude(is_active=0)
bgneal@56 17 return render(request, 'band/bio.html', {'members': members})
bgneal@43 18
bgneal@43 19
bgneal@43 20 def photos_index(request):
bgneal@43 21 galleries = Gallery.objects.values('title', 'id').order_by('-id')
bgneal@43 22
bgneal@56 23 photo_ids = Photo.objects.filter(is_public=True).values_list('id',
bgneal@56 24 flat=True)
bgneal@56 25 photo_ids = random.sample(photo_ids, 4)
bgneal@56 26 random_photos = Photo.objects.filter(id__in=photo_ids)
bgneal@43 27
bgneal@56 28 return render(request, 'band/photos.html', {
bgneal@56 29 'galleries': galleries,
bgneal@56 30 'random_photos': random_photos,
bgneal@56 31 })
bgneal@43 32
bgneal@43 33
bgneal@43 34 def photo_detail(request, id):
bgneal@56 35 gallery = get_object_or_404(Gallery, pk=id)
bgneal@43 36 photos = gallery.photos.order_by('id')
bgneal@56 37
bgneal@56 38 return render(request, 'band/photo_detail.html', {
bgneal@56 39 'gallery': gallery,
bgneal@56 40 'photos': photos,
bgneal@56 41 })
bgneal@1 42
bgneal@1 43
bgneal@1 44 def buy(request):
bgneal@43 45 albums = Album.objects.all().order_by('-id')
bgneal@43 46 merchandise = Merchandise.objects.all().order_by('-id')
bgneal@56 47 return render(request, 'band/buy.html', {
bgneal@43 48 'albums': albums,
bgneal@43 49 'merchandise': merchandise,
bgneal@56 50 })
bgneal@1 51
bgneal@1 52
bgneal@1 53 def contact(request):
bgneal@56 54 band = Member.objects.exclude(is_active=0).order_by('order')
bgneal@56 55 return render(request, 'band/contact.html', {
bgneal@43 56 'band': band,
bgneal@56 57 })