Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def date_archive(request, year, month) :
  2. """The blog date archive"""
  3. # this archive pages dates
  4. year = int(year)
  5. month = int(month)
  6. month_range = calendar.monthrange(year, month)
  7. start = datetime.datetime(year=year, month=month, day=1)#.replace(tzinfo=utc)
  8. end = datetime.datetime(year=year, month=month, day=month_range[1])#.replace(tzinfo=utc)
  9. archive_dates = Article.objects.dates('date_publish','month', order='DESC')
  10. categories = Category.objects.all()
  11.  
  12. # Pagination
  13. page = request.GET.get('page')
  14. article_queryset = Article.objects.filter(date_publish__range=(start.date(), end.date()))
  15. paginator = Paginator(article_queryset, 5)
  16.  
  17. try:
  18. articles = paginator.page(page)
  19. except PageNotAnInteger:
  20. # If page is not an integer, deliver first page.
  21. articles = paginator.page(1)
  22. except EmptyPage:
  23. # If page is out of range (e.g. 9999), deliver last page of results.
  24. articles = paginator.page(paginator.num_pages)
  25.  
  26. return render(
  27. request,
  28. "blog/article/date_archive.html",
  29. {
  30. "start" : start,
  31. "end" : end,
  32. "articles" : articles,
  33. "archive_dates" : archive_dates,
  34. "categories" : categories
  35. }
  36. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement