Mercurial > public > sg101
comparison ygroup/views.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/ygroup/views.py@0c18dfb1da1c |
children | 5d208c3321ce |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
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) |