diff band/views.py @ 71:e2868ad47a1e

For Django 1.4, using the new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2012 16:40:29 -0500
parents madeira/band/views.py@4579bbb6e053
children 2db040e89285
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/band/views.py	Sat Apr 14 16:40:29 2012 -0500
@@ -0,0 +1,57 @@
+"""
+Views for the band application.
+
+"""
+import random
+
+from django.shortcuts import render
+from django.shortcuts import get_object_or_404
+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=0)
+    return render(request, 'band/bio.html', {'members': members})
+
+
+def photos_index(request):
+    galleries = Gallery.objects.values('title', 'id').order_by('-id')
+
+    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(request, 'band/photos.html', {
+        'galleries': galleries,
+        'random_photos': random_photos,
+    })
+
+
+def photo_detail(request, id):
+    gallery = get_object_or_404(Gallery, pk=id)
+    photos = gallery.photos.order_by('id')
+
+    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(request, 'band/buy.html', {
+        'albums': albums, 
+        'merchandise': merchandise, 
+    })
+
+
+def contact(request):
+    band = Member.objects.exclude(is_active=0).order_by('order')
+    return render(request, 'band/contact.html', {
+        'band': band,
+    })