X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/acedb5e82f30e6502e2801db9f8d64d879f44347..refs/heads/django-4.2:/sommitrealweird/blog/views.py diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index 841b1ca..1f29f98 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -1,5 +1,6 @@ from blog.models import BlogEntry, BlogSection from django.http import Http404, HttpResponse +from django.shortcuts import render from django.template import RequestContext, loader from django.core.paginator import Paginator from django.conf import settings @@ -16,24 +17,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_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)) + try: + paginated_entries = paginator.page(page) + pages = paginator.page_range + c = { + "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 render(request, 'blog/blog_index.html', c) + except: + raise Http404 else: + return render(request, 'blog/blog_index.html') raise Http404 def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, section=None, slug=None): @@ -46,14 +49,11 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, 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, - { + c = { "entry": blog_entry, "publish_date": blog_entry.publish_date } - ) - return HttpResponse(t.render(c)) + return render(request, template_name, c) except: raise Http404 else: @@ -78,22 +78,23 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=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_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)) + try: + paginated_entries = paginator.page(page) + pages = paginator.page_range + c = { + "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 render(request, "blog/blog_index.html", c) + except: + raise Http404 else: raise Http404