from django.shortcuts import render_to_response from django.template import RequestContext from django.http import Http404, HttpResponse from django.core import serializers from photos.models import Photo, PhotoGallery from locations.models import Country, Region def gallery_list(request, page): request.page_url = '/photos/%d/' request.page = int(page) context = { 'object_list': PhotoGallery.objects.all(), 'page': page, } return render_to_response("archives/photos.html", context, context_instance=RequestContext(request)) def gallery(request, slug): context = { 'object': PhotoGallery.objects.get(set_slug=slug) } return render_to_response('details/photo_galleries.html', context, context_instance=RequestContext(request)) def photo_json(request, slug): p = PhotoGallery.objects.filter(set_slug=slug) return HttpResponse(serializers.serialize('json', p), mimetype='application/json') def gallery_list_by_area(request, slug, page): """Grabs entries by region or country""" request.page_url = '/photos/' + slug + '/%d/' request.page = int(page) try: region = Region.objects.get(slug__exact=slug) qs = PhotoGallery.objects.filter(region=region).order_by('-id') except: region = Country.objects.get(slug__exact=slug) qs = PhotoGallery.objects.filter(location__state__country=region).order_by('-id') if not region: raise Http404 context = { 'object_list': qs, 'country_list': Country.objects.filter(visited=True), 'region_list': Region.objects.all(), 'region': region, 'page': page } return render_to_response("archives/photos.html", context, context_instance=RequestContext(request))