annotate ygroup/views.py @ 887:9a15f7c27526

Actually save model object upon change. This commit was tested on the comments model. Additional logging added. Added check for Markdown image references. Added TODOs after observing behavior on comments.
author Brian Neal <bgneal@gmail.com>
date Tue, 03 Feb 2015 21:09:44 -0600
parents ee87ea74d46b
children 5d208c3321ce
rev   line source
bgneal@323 1 """
bgneal@323 2 Views for the ygroup (Yahoo Group Archive) application.
bgneal@323 3
bgneal@323 4 """
bgneal@323 5 from django.shortcuts import get_object_or_404
bgneal@323 6 from django.views.generic import ListView
bgneal@323 7
bgneal@323 8 from ygroup.models import Thread, Post
bgneal@323 9 from core.paginator import DiggPaginator
bgneal@323 10
bgneal@323 11
bgneal@323 12 THREADS_PER_PAGE = 40
bgneal@323 13 POSTS_PER_PAGE = 20
bgneal@323 14
bgneal@323 15
bgneal@323 16 class ThreadIndexView(ListView):
bgneal@323 17 """
bgneal@323 18 This generic view displays the list of threads available.
bgneal@323 19
bgneal@323 20 """
bgneal@323 21 model = Thread
bgneal@323 22 paginate_by = THREADS_PER_PAGE
bgneal@323 23
bgneal@323 24 def get_paginator(self, queryset, per_page, **kwargs):
bgneal@323 25 """
bgneal@323 26 Return an instance of the paginator for this view.
bgneal@323 27 """
bgneal@323 28 return DiggPaginator(queryset, per_page, body=5, tail=2,
bgneal@323 29 margin=3, padding=2, **kwargs)
bgneal@323 30
bgneal@323 31
bgneal@323 32 class ThreadView(ListView):
bgneal@323 33 """
bgneal@323 34 This generic view displays the posts in a thread.
bgneal@323 35
bgneal@323 36 """
bgneal@323 37 context_object_name = "post_list"
bgneal@323 38 template_name = "ygroup/thread.html"
bgneal@323 39 paginate_by = POSTS_PER_PAGE
bgneal@323 40
bgneal@323 41 def get_queryset(self):
bgneal@323 42 self.thread = get_object_or_404(Thread, pk=self.args[0])
bgneal@323 43 return Post.objects.filter(thread=self.thread)
bgneal@323 44
bgneal@323 45 def get_context_data(self, **kwargs):
bgneal@323 46 context = super(ThreadView, self).get_context_data(**kwargs)
bgneal@323 47 context['thread'] = self.thread
bgneal@323 48 return context
bgneal@323 49
bgneal@323 50 def get_paginator(self, queryset, per_page, **kwargs):
bgneal@323 51 """
bgneal@323 52 Return an instance of the paginator for this view.
bgneal@323 53 """
bgneal@323 54 return DiggPaginator(queryset, per_page, body=5, tail=2,
bgneal@323 55 margin=3, padding=2, **kwargs)