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@1080: from django.views.generic import ListView, DetailView 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@1045: template_name = 'ygroup/v3/thread_list.html' bgneal@1045: bgneal@1045: def get_context_data(self, **kwargs): bgneal@1045: context = super(ThreadIndexView, self).get_context_data(**kwargs) bgneal@1045: context['V3_DESIGN'] = True bgneal@1045: 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) 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@1045: template_name = "ygroup/v3/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@1045: context['V3_DESIGN'] = True 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) bgneal@1080: bgneal@1080: bgneal@1080: class PostView(DetailView): bgneal@1080: model = Post bgneal@1080: context_object_name = 'post' bgneal@1080: template_name = 'ygroup/v3/post.html' bgneal@1080: bgneal@1080: def get_context_data(self, **kwargs): bgneal@1080: context = super(PostView, self).get_context_data(**kwargs) bgneal@1080: context['V3_DESIGN'] = True bgneal@1080: return context