X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/2d5a803e2b8bd6ed72de946d4cfbb7b880493bf6..ea07b61ca29ec3ad3c048a258b8a6472bf679da7:/sommitrealweird/blog/views.py?ds=sidebyside diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index b01bec8..09ff5e4 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -16,22 +16,26 @@ def blog_index(request, section=None): 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_next": paginated_entries.has_next(), - "has_prev": paginated_entries.has_previous(), - "next": page + 1, - "prev": page - 1 - }) - return HttpResponse(t.render(c)) + try: + 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)) + except: + raise Http404 else: raise Http404 @@ -42,13 +46,60 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, year = int(year) month = int(month) day = int(day) - blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug) - template_name = "blog/single_entry_%s.html" %(blog_entry.format,) - t = loader.get_template(template_name) - c = RequestContext(request, - { - "entry": blog_entry, - "publish_date": blog_entry.publish_date - } - ) - return HttpResponse(t.render(c)) + try: + blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug) + template_name = "blog/single_entry_%s.html" %(blog_entry.format,) + t = loader.get_template(template_name) + c = RequestContext(request, + { + "entry": blog_entry, + "publish_date": blog_entry.publish_date + } + ) + return HttpResponse(t.render(c)) + except: + raise Http404 + 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 + try: + 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)) + except: + raise Http404 + else: + raise Http404