[PATCH] do not show archive entries for the date before the first post

5 views
Skip to first unread message

Denis

unread,
Nov 3, 2010, 6:31:00 PM11/3/10
to byteflow...@googlegroups.com
# HG changeset patch
# User Denis <denis@localhost>
# Date 1288735569 -3600
# Node ID 5e3f38e43fd3c0f8d23ec9b60dce6ff421c697cb
# Parent c36944d45994f034adf5e505cb58ca3093c99ef3
do not show archive entries for the date before the first post

diff -r c36944d45994 -r 5e3f38e43fd3 apps/blog/views.py
--- a/apps/blog/views.py Wed May 19 18:13:12 2010 +0300
+++ b/apps/blog/views.py Tue Nov 02 23:06:09 2010 +0100
@@ -54,6 +54,14 @@
def archive_month(request, year, month):
if int(year) < 1901: # to exclude all troubles with strftime
raise Http404
+ first_post = Post.objects.order_by('date')[0]
+ min_year = first_post.date.date().year
+ min_month = first_post.date.date().month
+ try:
+ if dt(int(year), int(month), 1) < dt(int(min_year), int(min_month), 1):
+ return HttpResponseRedirect('/%s' % settings.BLOG_URLCONF_ROOT)
+ except (ValueError):
+ return HttpResponseRedirect('/%s' % settings.BLOG_URLCONF_ROOT)
qs = Post.objects.all()
return date_based.archive_month(request, year, month, queryset=qs,
month_format='%m',
@@ -64,6 +72,10 @@
def archive_year(request, year):
if int(year) < 1901:
raise Http404
+ first_post = Post.objects.order_by('date')[0]
+ min_year = first_post.date.date().year
+ if int(year) < min_year:
+ return HttpResponseRedirect('/%s' % settings.BLOG_URLCONF_ROOT)
qs = Post.objects.all()
return date_based.archive_year(request, year, make_object_list=True,
queryset=qs,
@@ -74,6 +86,15 @@
def archive_day(request, year, month, day):
if int(year) < 1901:
raise Http404
+ first_post = Post.objects.order_by('date')[0]
+ min_year = first_post.date.date().year
+ min_month = first_post.date.date().month
+ min_day = first_post.date.date().day
+ try:
+ if dt(int(year), int(month), int(day)) < dt(int(min_year), int(min_month), int(min_day)):
+ return HttpResponseRedirect('/%s' % settings.BLOG_URLCONF_ROOT)
+ except (ValueError):
+ return HttpResponseRedirect('/%s' % settings.BLOG_URLCONF_ROOT)
qs = Post.objects.all()
return date_based.archive_day(request, year, month, day, month_format='%m',
template_name='blog/post_archive_year.html',

Alexander Solovyov

unread,
Nov 5, 2010, 1:47:28 PM11/5/10
to byteflow...@googlegroups.com
On Wed, Nov 3, 2010 at 23:31, Denis <goo...@syslog.net.ru> wrote:
> # HG changeset patch
> # User Denis <denis@localhost>
> # Date 1288735569 -3600
> # Node ID 5e3f38e43fd3c0f8d23ec9b60dce6ff421c697cb
> # Parent  c36944d45994f034adf5e505cb58ca3093c99ef3
> do not show archive entries for the date before the first post

Thanks, all three patches applied and pushed.

--
Alexander

Reply all
Reply to author
Forward
0 new messages