def archive(request, page=1, year=None, month=None, day=None): """ Blog post archive """ posts = Post.objects.filter(published=True).prefetch_related('author') paginator = Paginator(posts, 5) page_posts = paginator.get_page(page) return cacheatron( request, render(request, 'blog/archive.html', {'posts': page_posts}), (zxpost, ))
def home(request): """ Homepage """ chapters = Chapter.only_published().prefetch_related('team', 'comic') posts = Post.objects.filter(published=True).prefetch_related('author')[:5] return cacheatron( request, render(request, 'blog/home.html', {'chapters': chapters, 'posts': posts}), (zxpost, zxchapter) )
def post(request, year, month, day, slug): """ Blog posts """ try: cdate = date(year, month, day) except ValueError: raise Http404 blog_post = get_object_or_404(Post, slug=slug, created_at__contains=cdate) return cacheatron(request, render(request, 'blog/post.html', {'post': blog_post}), (zxpost, ))
def page(request, url): """ Attempt to find a flatpage for the path and display it """ if not url.startswith('/'): url = '/' + url site_id = get_current_site(request).id try: f = get_object_or_404(Page, url=url, sites=site_id) except Http404: if not url.endswith('/') and settings.APPEND_SLASH: url += '/' f = get_object_or_404(Page, url=url, sites=site_id) return HttpResponsePermanentRedirect('%s/' % request.path) else: raise return cacheatron(request, render_flatpage(request, f), (zxpage,))