Add date listing function
This commit is contained in:
parent
9bc614f8a0
commit
4274455957
@ -6,6 +6,8 @@ urlpatterns = patterns('',
|
|||||||
url(r'^page/(?P<page>\d+)$', views.indexpage, name = 'indexpage'),
|
url(r'^page/(?P<page>\d+)$', views.indexpage, name = 'indexpage'),
|
||||||
url(r'^tag/(?P<tag>[^/]+)$', views.taglist, name = 'taglist'),
|
url(r'^tag/(?P<tag>[^/]+)$', views.taglist, name = 'taglist'),
|
||||||
url(r'^tag/(?P<tag>[^/]+)/page/(?P<page>\d+)$', views.tagpage, name = 'tagpage'),
|
url(r'^tag/(?P<tag>[^/]+)/page/(?P<page>\d+)$', views.tagpage, name = 'tagpage'),
|
||||||
|
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/?$', views.datelist, name = 'datelist'),
|
||||||
|
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/page/(?P<page>\d+)$', views.datepage, name = 'datepage'),
|
||||||
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<slug>[^/]+)$', views.read, name = 'read'),
|
url(r'^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<slug>[^/]+)$', views.read, name = 'read'),
|
||||||
url(r'^code-chunk/(?P<language>[^/]+)/(?P<slug>[^/]+)$', views.codechunk, name = 'codechunk'),
|
url(r'^code-chunk/(?P<language>[^/]+)/(?P<slug>[^/]+)$', views.codechunk, name = 'codechunk'),
|
||||||
url(r'^feed$', views.feed, name = 'feed'),
|
url(r'^feed$', views.feed, name = 'feed'),
|
||||||
|
@ -7,14 +7,27 @@ def mainpage(request):
|
|||||||
last_posts = Post.objects.filter(draft = False).order_by('-created_at')[:5]
|
last_posts = Post.objects.filter(draft = False).order_by('-created_at')[:5]
|
||||||
return render(request, 'blog/listing.html', {'posts': last_posts})
|
return render(request, 'blog/listing.html', {'posts': last_posts})
|
||||||
|
|
||||||
def listing(request, tag, page):
|
def listing(request, tag, year, month, day, page):
|
||||||
|
kwargs = {}
|
||||||
|
kwargs['draft'] = False
|
||||||
|
|
||||||
|
view = index
|
||||||
if (tag == None):
|
if (tag == None):
|
||||||
post_list = Post.objects.filter(draft = False)
|
|
||||||
view = "index"
|
view = "index"
|
||||||
else:
|
else:
|
||||||
post_list = Post.objects.filter(tags__slug = tag, draft = False)
|
kwargs['tags__slug'] = tag
|
||||||
view = "tag"
|
view = "tagpage"
|
||||||
|
|
||||||
|
if (year != None):
|
||||||
|
kwargs['created_at__year'] = year
|
||||||
|
|
||||||
|
if (month != None):
|
||||||
|
kwargs['created_at__month'] = month
|
||||||
|
|
||||||
|
if (day != None):
|
||||||
|
kwargs['created_at__day'] = day
|
||||||
|
|
||||||
|
post_list = Post.objects.filter(**kwargs)
|
||||||
paginator = Paginator(post_list.order_by('-created_at'), 10)
|
paginator = Paginator(post_list.order_by('-created_at'), 10)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -27,16 +40,22 @@ def listing(request, tag, page):
|
|||||||
return render(request, 'blog/listing.html', { 'posts': posts, 'view': "blog:" + view })
|
return render(request, 'blog/listing.html', { 'posts': posts, 'view': "blog:" + view })
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
return listing(request, None, 1)
|
return listing(request, None, None, None, None, 1)
|
||||||
|
|
||||||
def indexpage(request, page):
|
def indexpage(request, page):
|
||||||
return listing(request, None, page)
|
return listing(request, None, None, None, None, page)
|
||||||
|
|
||||||
def taglist(request, tag):
|
def taglist(request, tag):
|
||||||
return listing(request, tag, 1)
|
return listing(request, tag, None, None, None, 1)
|
||||||
|
|
||||||
def tagpage(request, tag, page):
|
def tagpage(request, tag, page):
|
||||||
return listing(request, tag, page)
|
return listing(request, tag, None, None, None, page)
|
||||||
|
|
||||||
|
def datelist(request, year, month, day):
|
||||||
|
return listing(request, None, year, month, day, 1)
|
||||||
|
|
||||||
|
def datepage(request, year, month, day, page):
|
||||||
|
return listing(request, None, year, month, day, page)
|
||||||
|
|
||||||
def read(request, year, month, day, slug):
|
def read(request, year, month, day, slug):
|
||||||
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug, draft=False)
|
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug, draft=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user