views.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(
  11. "historical/index.html", locals(), context_instance=RequestContext(request)
  12. )
  13. def group_detail(request, slug):
  14. object = get_object_or_404(Group, slug=slug)
  15. if object.template_name:
  16. t = loader.select_template((object.template_name, DEFAULT_TEMPLATE))
  17. else:
  18. t = loader.get_template(DEFAULT_TEMPLATE)
  19. c = RequestContext(request, {"object": object,})
  20. response = HttpResponse(t.render(c))
  21. populate_xheaders(request, response, Group, object.id)
  22. return response
  23. def article_detail(request, group_slug, year, month, day, slug):
  24. object = (
  25. HistoricArticle.objects.published()
  26. .filter(group__slug=group_slug)
  27. .get(story__slug=slug)
  28. )
  29. return render_to_response(
  30. "historical/article_detail.html",
  31. locals(),
  32. context_instance=RequestContext(request),
  33. )
  34. def article_archive_year(request, group_slug, year):
  35. objects = HistoricArticle.objects.filter(
  36. group__slug=group_slug, published_on__year=year
  37. )
  38. return render_to_response(
  39. "historical/article_archive_year.html",
  40. locals(),
  41. context_instance=RequestContext(request),
  42. )
  43. def article_archive_month(request, group_slug, year, month):
  44. date = datetime.date(int(year), int(month), 1)
  45. objects = HistoricArticle.objects.filter(
  46. group__slug=group_slug,
  47. story__published_on__year=year,
  48. story__published_on__month=date.month,
  49. )
  50. return render_to_response(
  51. "historical/article_archive_month.html",
  52. locals(),
  53. context_instance=RequestContext(request),
  54. )
  55. def article_archive_day(request, group_slug, year, month, day):
  56. date = datetime.date(int(year), int(month), int(day))
  57. objects = HistoricArticle.objects.filter(
  58. group__slug=group_slug,
  59. story__published_on__year=year,
  60. story__published_on__month=date.month,
  61. story__published_on__day=date.day,
  62. )
  63. return render_to_response(
  64. "historical/article_archive_year.html",
  65. locals(),
  66. context_instance=RequestContext(request),
  67. )