bgneal@323: """ bgneal@323: Views for the ygroup (Yahoo Group Archive) application. bgneal@323: bgneal@323: """ bgneal@323: from django.shortcuts import get_object_or_404 bgneal@323: from django.views.generic import ListView bgneal@323: bgneal@323: from ygroup.models import Thread, Post bgneal@323: from core.paginator import DiggPaginator bgneal@323: bgneal@323: bgneal@323: THREADS_PER_PAGE = 40 bgneal@323: POSTS_PER_PAGE = 20 bgneal@323: bgneal@323: bgneal@323: class ThreadIndexView(ListView): bgneal@323: """ bgneal@323: This generic view displays the list of threads available. bgneal@323: bgneal@323: """ bgneal@323: model = Thread bgneal@323: paginate_by = THREADS_PER_PAGE bgneal@323: bgneal@323: def get_paginator(self, queryset, per_page, **kwargs): bgneal@323: """ bgneal@323: Return an instance of the paginator for this view. bgneal@323: """ bgneal@323: return DiggPaginator(queryset, per_page, body=5, tail=2, bgneal@323: margin=3, padding=2, **kwargs) bgneal@323: bgneal@323: bgneal@323: class ThreadView(ListView): bgneal@323: """ bgneal@323: This generic view displays the posts in a thread. bgneal@323: bgneal@323: """ bgneal@323: context_object_name = "post_list" bgneal@323: template_name = "ygroup/thread.html" bgneal@323: paginate_by = POSTS_PER_PAGE bgneal@323: bgneal@323: def get_queryset(self): bgneal@323: self.thread = get_object_or_404(Thread, pk=self.args[0]) bgneal@323: return Post.objects.filter(thread=self.thread) bgneal@323: bgneal@323: def get_context_data(self, **kwargs): bgneal@323: context = super(ThreadView, self).get_context_data(**kwargs) bgneal@323: context['thread'] = self.thread bgneal@323: return context bgneal@323: bgneal@323: def get_paginator(self, queryset, per_page, **kwargs): bgneal@323: """ bgneal@323: Return an instance of the paginator for this view. bgneal@323: """ bgneal@323: return DiggPaginator(queryset, per_page, body=5, tail=2, bgneal@323: margin=3, padding=2, **kwargs)