from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.http import Http404 from django.conf import settings # from django.views.generic import ListView from blog.models import Entry, HomepageCurrator from locations.models import Region, Country from photos.models import Photo def home(request): obj = HomepageCurrator.objects.get(pk=1) template = obj.template_name recent = Entry.objects.filter(status__exact=1)[:4] context = { 'IMAGES_URL': settings.IMAGES_URL, 'homepage': obj, 'recent': recent, } return render_to_response(template, context, context_instance=RequestContext(request)) def entry_detail(request, year, month, 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 class BlogEntryListView(ListView): template_name="archives/writing.html" model = Entry def get_context_data(self, **kwargs): context = super(BlogEntryListView, self).get_context_data(**kwargs) context.update({ 'page': self.kwargs['page'] }) self.request.page_url = '/writing/%d/' self.request.page = self.kwargs['page'] return context """ def date_list(request, year, month=None): import datetime if month: month_name = datetime.datetime.strptime(month,'%m').strftime('%B') context = { 'object_list': Entry.objects.filter(status__exact=1, pub_date__year=year, pub_date__month=month).order_by('pub_date'), 'type': 'monthly', 'year': year, 'month': month_name } else: context = { 'object_list': Entry.objects.filter(status__exact=1, pub_date__year=year).order_by('-pub_date'), 'type': 'year', 'year': year, } return render_to_response("archives/writing_date.html", context, context_instance=RequestContext(request)) def entry_list(request, page): request.page_url = '/jrnl/%d/' request.page = int(page) try: is_build = request.POST['builder'] extra_context={ 'page':page, 'MEDIA_URL': settings.BAKED_MEDIA_URL } except: extra_context={'page':page} context = { 'object_list': Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related(), 'page': page } return render_to_response("archives/writing.html", context, context_instance=RequestContext(request)) def entry_list_by_area(request, slug, page): """ Grabs entries by region or country""" request.page_url = '/jrnl/' + slug + '/%d/' request.page = int(page) try: region = Region.objects.get(slug__exact=slug) qs = Entry.objects.filter(status__exact=1, location__state__country__lux_region=region.id).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, 'object_list': qs, 'page': page } return render_to_response("archives/writing.html", context, context_instance=RequestContext(request))