views.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. DEFAULT_TEMPLATE = 'historical/group/default.html'
  2. import datetime
  3. from django.template.context import RequestContext
  4. from django.shortcuts import render_to_response, get_object_or_404
  5. from django.template import loader
  6. from django.http import HttpResponse
  7. from django.core.xheaders import populate_xheaders
  8. from historical.models import *
  9. def index(request):
  10. return render_to_response('historical/index.html', locals(),
  11. context_instance=RequestContext(request))
  12. def group_detail(request, slug):
  13. object=get_object_or_404(Group, slug=slug)
  14. if object.template_name:
  15. t = loader.select_template((object.template_name, DEFAULT_TEMPLATE))
  16. else:
  17. t = loader.get_template(DEFAULT_TEMPLATE)
  18. c = RequestContext(request, {
  19. 'object': object,
  20. })
  21. response = HttpResponse(t.render(c))
  22. populate_xheaders(request, response, Group, object.id)
  23. return response
  24. def article_detail(request, group_slug, year, month, day, slug):
  25. object=HistoricArticle.objects.published().filter(group__slug=group_slug).get(story__slug=slug)
  26. return render_to_response('historical/article_detail.html', locals(),
  27. context_instance=RequestContext(request))
  28. def article_archive_year(request, group_slug, year):
  29. objects=HistoricArticle.objects.filter(group__slug=group_slug, published_on__year=year)
  30. return render_to_response('historical/article_archive_year.html', locals(),
  31. context_instance=RequestContext(request))
  32. def article_archive_month(request, group_slug, year, month):
  33. date=datetime.date(int(year), int(month), 1)
  34. objects=HistoricArticle.objects.filter(group__slug=group_slug, story__published_on__year=year, story__published_on__month=date.month)
  35. return render_to_response('historical/article_archive_month.html', locals(),
  36. context_instance=RequestContext(request))
  37. def article_archive_day(request, group_slug, year, month, day):
  38. date=datetime.date(int(year), int(month), int(day))
  39. objects=HistoricArticle.objects.filter(group__slug=group_slug, story__published_on__year=year, story__published_on__month=date.month, story__published_on__day=date.day)
  40. return render_to_response('historical/article_archive_year.html', locals(),
  41. context_instance=RequestContext(request))