Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def date_archive(request, year, month) :
- """The blog date archive"""
- # this archive pages dates
- year = int(year)
- month = int(month)
- month_range = calendar.monthrange(year, month)
- start = datetime.datetime(year=year, month=month, day=1)#.replace(tzinfo=utc)
- end = datetime.datetime(year=year, month=month, day=month_range[1])#.replace(tzinfo=utc)
- archive_dates = Article.objects.dates('date_publish','month', order='DESC')
- categories = Category.objects.all()
- # Pagination
- page = request.GET.get('page')
- article_queryset = Article.objects.filter(date_publish__range=(start.date(), end.date()))
- paginator = Paginator(article_queryset, 5)
- try:
- articles = paginator.page(page)
- except PageNotAnInteger:
- # If page is not an integer, deliver first page.
- articles = paginator.page(1)
- except EmptyPage:
- # If page is out of range (e.g. 9999), deliver last page of results.
- articles = paginator.page(paginator.num_pages)
- return render(
- request,
- "blog/article/date_archive.html",
- {
- "start" : start,
- "end" : end,
- "articles" : articles,
- "archive_dates" : archive_dates,
- "categories" : categories
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement