1 from blog.models import BlogEntry, BlogSection
2 from django.http import Http404, HttpResponse
3 from django.shortcuts import render
4 from django.template import RequestContext, loader
5 from django.core.paginator import Paginator
6 from django.conf import settings
8 def blog_index(request, section=None):
9 entries = BlogEntry.objects.all()
11 entries = entries.filter(sections__slug__exact=section)
12 entries = entries.order_by('-publish_date')
15 paginator = Paginator(entries, paginate_by)
17 page = int(request.GET.get('page', 1))
21 paginated_entries = paginator.page(page)
22 pages = paginator.page_range
24 "entries": paginated_entries.object_list,
25 "title": settings.BLOG_TITLE,
29 "has_more_than_one_page": (len(pages) > 1),
30 "has_next": paginated_entries.has_next(),
31 "has_prev": paginated_entries.has_previous(),
35 return render(request, 'blog/blog_index.html', c)
39 return render(request, 'blog/blog_index.html')
42 def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, section=None, slug=None):
43 # work out what we've got roughly
44 if year and month and day and slug:
45 # exact blog entry (woo!)
50 blog_entry = BlogEntry.objects.get(publish_date__year=year, publish_date__month=month, publish_date__day=day, slug__exact=slug)
51 template_name = "blog/single_entry_%s.html" %(blog_entry.format,)
54 "publish_date": blog_entry.publish_date
56 return render(request, template_name, c)
60 entries = BlogEntry.objects.all()
61 if year and month and day:
65 entries = entries.filter(publish_date__year=year, publish_date__month=month, publish_date__day=day)
69 entries = entries.filter(publish_date__year=year, publish_date__month=month)
72 entries = entries.filter(publish_date__year=year)
74 entries = entries.order_by('-publish_date')
76 paginator = Paginator(entries, paginate_by)
78 page = int(request.GET.get('page', 1))
82 paginated_entries = paginator.page(page)
83 pages = paginator.page_range
85 "entries": paginated_entries.object_list,
86 "title": settings.BLOG_TITLE,
90 "has_more_than_one_page": (len(pages) > 1),
91 "has_next": paginated_entries.has_next(),
92 "has_prev": paginated_entries.has_previous(),
96 return render(request, "blog/blog_index.html", c)