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@1045
|
23 template_name = 'ygroup/v3/thread_list.html'
|
bgneal@1045
|
24
|
bgneal@1045
|
25 def get_context_data(self, **kwargs):
|
bgneal@1045
|
26 context = super(ThreadIndexView, self).get_context_data(**kwargs)
|
bgneal@1045
|
27 context['V3_DESIGN'] = True
|
bgneal@1045
|
28 return context
|
bgneal@323
|
29
|
bgneal@323
|
30 def get_paginator(self, queryset, per_page, **kwargs):
|
bgneal@323
|
31 """
|
bgneal@323
|
32 Return an instance of the paginator for this view.
|
bgneal@323
|
33 """
|
bgneal@323
|
34 return DiggPaginator(queryset, per_page, body=5, tail=2,
|
bgneal@323
|
35 margin=3, padding=2, **kwargs)
|
bgneal@323
|
36
|
bgneal@323
|
37
|
bgneal@323
|
38 class ThreadView(ListView):
|
bgneal@323
|
39 """
|
bgneal@323
|
40 This generic view displays the posts in a thread.
|
bgneal@323
|
41
|
bgneal@323
|
42 """
|
bgneal@323
|
43 context_object_name = "post_list"
|
bgneal@1045
|
44 template_name = "ygroup/v3/thread.html"
|
bgneal@323
|
45 paginate_by = POSTS_PER_PAGE
|
bgneal@323
|
46
|
bgneal@323
|
47 def get_queryset(self):
|
bgneal@323
|
48 self.thread = get_object_or_404(Thread, pk=self.args[0])
|
bgneal@323
|
49 return Post.objects.filter(thread=self.thread)
|
bgneal@323
|
50
|
bgneal@323
|
51 def get_context_data(self, **kwargs):
|
bgneal@323
|
52 context = super(ThreadView, self).get_context_data(**kwargs)
|
bgneal@323
|
53 context['thread'] = self.thread
|
bgneal@1045
|
54 context['V3_DESIGN'] = True
|
bgneal@323
|
55 return context
|
bgneal@323
|
56
|
bgneal@323
|
57 def get_paginator(self, queryset, per_page, **kwargs):
|
bgneal@323
|
58 """
|
bgneal@323
|
59 Return an instance of the paginator for this view.
|
bgneal@323
|
60 """
|
bgneal@323
|
61 return DiggPaginator(queryset, per_page, body=5, tail=2,
|
bgneal@323
|
62 margin=3, padding=2, **kwargs)
|