Mercurial > public > sg101
comparison gpp/ygroup/views.py @ 323:0c18dfb1da1c
Fixing #149; adding the ygroup application: an archive of the old Yahoo Group messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 20 Feb 2011 00:31:54 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
322:c3d3d7114749 | 323:0c18dfb1da1c |
---|---|
1 """ | |
2 Views for the ygroup (Yahoo Group Archive) application. | |
3 | |
4 """ | |
5 from django.shortcuts import get_object_or_404 | |
6 from django.views.generic import ListView | |
7 | |
8 from ygroup.models import Thread, Post | |
9 from core.paginator import DiggPaginator | |
10 | |
11 | |
12 THREADS_PER_PAGE = 40 | |
13 POSTS_PER_PAGE = 20 | |
14 | |
15 | |
16 class ThreadIndexView(ListView): | |
17 """ | |
18 This generic view displays the list of threads available. | |
19 | |
20 """ | |
21 model = Thread | |
22 paginate_by = THREADS_PER_PAGE | |
23 | |
24 def get_paginator(self, queryset, per_page, **kwargs): | |
25 """ | |
26 Return an instance of the paginator for this view. | |
27 """ | |
28 return DiggPaginator(queryset, per_page, body=5, tail=2, | |
29 margin=3, padding=2, **kwargs) | |
30 | |
31 | |
32 class ThreadView(ListView): | |
33 """ | |
34 This generic view displays the posts in a thread. | |
35 | |
36 """ | |
37 context_object_name = "post_list" | |
38 template_name = "ygroup/thread.html" | |
39 paginate_by = POSTS_PER_PAGE | |
40 | |
41 def get_queryset(self): | |
42 self.thread = get_object_or_404(Thread, pk=self.args[0]) | |
43 return Post.objects.filter(thread=self.thread) | |
44 | |
45 def get_context_data(self, **kwargs): | |
46 context = super(ThreadView, self).get_context_data(**kwargs) | |
47 context['thread'] = self.thread | |
48 return context | |
49 | |
50 def get_paginator(self, queryset, per_page, **kwargs): | |
51 """ | |
52 Return an instance of the paginator for this view. | |
53 """ | |
54 return DiggPaginator(queryset, per_page, body=5, tail=2, | |
55 margin=3, padding=2, **kwargs) |