from django.shortcuts import render_to_response,get_object_or_404 from django.template import RequestContext from django.views.generic.date_based import object_detail from django.views.generic.list_detail import object_list from django.http import Http404 from django.conf import settings from blog.models import Entry, Topic from locations.models import Region, Country from photos.models import Photo, PhotoGallery from chunks.models import Chunk def home(request): featured = Entry.objects.filter(status__exact=1).latest() gallery = PhotoGallery.objects.latest() context = { 'featured': featured, 'gallery': gallery } return render_to_response('archives/homepage.html', context, context_instance = RequestContext(request)) def entry_detail(request, year, month, day, slug): obj = get_object_or_404(Entry, slug__exact=slug) photos = {} #if obj.photo_gallery: # photos = Photo.objects.filter(set__exact=obj.get().photo_gallery.id)[:9] extra = {'photos':photos,} return render_to_response('details/entry.html', {'object': obj,'photos':photos}, context_instance=RequestContext(request)) """ List of all writing """ def entry_list(request,page): request.page_url = '/writing/%d/' request.page = int(page) qs = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related() return object_list(request, queryset=qs, template_name='archives/writing.html') """ List of all writing """ def topic_list(request,slug,page): request.page_url = '/topics/'+slug+'/%d/' request.page = int(page) topic = Topic.objects.get(slug=slug) qs = Entry.objects.filter(status__exact=1,topics=topic).order_by('-pub_date').select_related() return object_list(request, queryset=qs, template_name='archives/topics.html',) """ Grabs entries by region or country """ def entry_list_by_area(request,slug,page): request.page_url = '/writing/'+slug+'/%d/' request.page = int(page) try: region = Region.objects.get(slug__exact=slug) qs = Entry.objects.filter(status__exact=1,region = region).order_by('-pub_date') except: region = Country.objects.get(slug__exact=slug) qs = Entry.objects.filter(status__exact=1,location__state__country = region).order_by('-pub_date') if not region: raise Http404 context = { 'region': region, } return object_list(request, queryset=qs, template_name='archives/writing.html', extra_context=context) def about(request): top = Chunk.objects.get(key='about_top') middle = Chunk.objects.get(key='about_middle') bottom = Chunk.objects.get(key='about_bottom') context = { 'top': top, 'middle': middle, 'bottom': bottom, 'IMAGES_URL' : settings.IMAGES_URL } return render_to_response('details/about.html', context, context_instance=RequestContext(request))