bgneal@43: """ bgneal@43: Views for the band application. bgneal@43: bgneal@43: """ bgneal@28: import random bgneal@28: bgneal@56: from django.shortcuts import render bgneal@1: from django.shortcuts import get_object_or_404 bgneal@40: from photologue.models import Gallery bgneal@40: from photologue.models import Photo bgneal@1: bgneal@56: from band.models import Member, Merchandise, Album bgneal@56: bgneal@43: bgneal@43: def bio(request): bgneal@56: members = Member.objects.exclude(is_active=0) bgneal@56: return render(request, 'band/bio.html', {'members': members}) bgneal@43: bgneal@43: bgneal@43: def photos_index(request): bgneal@141: galleries = Gallery.objects.values('title', 'id').order_by('-date_added') bgneal@43: bgneal@56: photo_ids = Photo.objects.filter(is_public=True).values_list('id', bgneal@56: flat=True) bgneal@56: photo_ids = random.sample(photo_ids, 4) bgneal@56: random_photos = Photo.objects.filter(id__in=photo_ids) bgneal@43: bgneal@56: return render(request, 'band/photos.html', { bgneal@56: 'galleries': galleries, bgneal@56: 'random_photos': random_photos, bgneal@56: }) bgneal@43: bgneal@43: bgneal@43: def photo_detail(request, id): bgneal@56: gallery = get_object_or_404(Gallery, pk=id) bgneal@43: photos = gallery.photos.order_by('id') bgneal@56: bgneal@56: return render(request, 'band/photo_detail.html', { bgneal@56: 'gallery': gallery, bgneal@56: 'photos': photos, bgneal@56: }) bgneal@1: bgneal@1: bgneal@1: def buy(request): bgneal@43: albums = Album.objects.all().order_by('-id') bgneal@43: merchandise = Merchandise.objects.all().order_by('-id') bgneal@56: return render(request, 'band/buy.html', { bgneal@180: 'albums': albums, bgneal@180: 'merchandise': merchandise, bgneal@56: }) bgneal@1: bgneal@1: bgneal@1: def contact(request): bgneal@56: band = Member.objects.exclude(is_active=0).order_by('order') bgneal@56: return render(request, 'band/contact.html', { bgneal@43: 'band': band, bgneal@56: })