"page": page,
"pages": pages,
"paginated": 1,
+ "has_more_than_one_page": (len(pages) > 1),
"has_next": paginated_entries.has_next(),
"has_prev": paginated_entries.has_previous(),
"next": page + 1,
}
)
return HttpResponse(t.render(c))
+ else:
+ entries = BlogEntry.objects.all()
+ if year and month and day:
+ year = int(year)
+ month = int(month)
+ day = int(day)
+ entries = entries.filter(publish_date__year=year, publish_date__month=month, publish_date__day=day)
+ elif year and month:
+ year = int(year)
+ month = int(month)
+ entries = entries.filter(publish_date__year=year, publish_date__month=month)
+ elif year:
+ year = int(year)
+ entries = entries.filter(publish_date__year=year)
+ if entries:
+ entries = entries.order_by('-publish_date')
+ paginate_by=20
+ paginator = Paginator(entries, paginate_by)
+ try:
+ page = int(request.GET.get('page', 1))
+ except ValueError:
+ page = 1
+ paginated_entries = paginator.page(page)
+ pages = paginator.page_range
+ t = loader.get_template("blog/blog_index.html")
+ c = RequestContext(request,
+ {
+ "entries": paginated_entries.object_list,
+ "title": settings.BLOG_TITLE,
+ "page": page,
+ "pages": pages,
+ "paginated": 1,
+ "has_more_than_one_page": (len(pages) > 1),
+ "has_next": paginated_entries.has_next(),
+ "has_prev": paginated_entries.has_previous(),
+ "next": page + 1,
+ "prev": page - 1
+ })
+ return HttpResponse(t.render(c))
+ else:
+ raise Http404