My favorites
▼
|
Sign in
django-forum
Simple Django Forum Component
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
31
attachment: pagination.patch
(4.9 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
Index: forum/admin.py
===================================================================
--- forum/admin.py (revision 24)
+++ forum/admin.py (working copy)
@@ -8,7 +8,11 @@
class SubscriptionAdmin(admin.ModelAdmin):
list_display = ['author','thread']
+class ThreadAdmin(admin.ModelAdmin):
+ list_display = ('title', 'forum', 'latest_post_time')
+ list_filter = ('forum',)
+
admin.site.register(Forum, ForumAdmin)
-admin.site.register(Thread)
+admin.site.register(Thread, ThreadAdmin)
admin.site.register(Post)
admin.site.register(Subscription, SubscriptionAdmin)
Index: forum/views.py
===================================================================
--- forum/views.py (revision 24)
+++ forum/views.py (working copy)
@@ -15,7 +15,7 @@
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
-
+from django.views.generic.list_detail import object_list
def forum(request, slug):
"""
Displays a list of threads within a forum.
@@ -24,11 +24,14 @@
"""
f = get_object_or_404(Forum, slug=slug)
- return render_to_response('forum/thread_list.html',
- RequestContext(request, {
- 'forum': f,
- 'threads': f.thread_set.all()
- }))
+ return object_list( request,
+ queryset=f.thread_set.all(),
+ paginate_by=10,
+ template_object_name='thread',
+ template_name='forum/thread_list.html',
+ extra_context = {
+ 'forum': f,
+ })
def thread(request, thread):
"""
@@ -42,13 +45,16 @@
t.views += 1
t.save()
- return render_to_response('forum/thread.html',
- RequestContext(request, {
- 'forum': t.forum,
- 'thread': t,
- 'posts': p,
- 'subscription': s,
- }))
+ return object_list( request,
+ queryset=p,
+ paginate_by=10,
+ template_object_name='post',
+ template_name='forum/thread.html',
+ extra_context = {
+ 'forum': t.forum,
+ 'thread': t,
+ 'subscription': s,
+ })
def reply(request, thread):
"""
Index: forum/templates/forum_base.html
===================================================================
--- forum/templates/forum_base.html (revision 24)
+++ forum/templates/forum_base.html (working copy)
@@ -78,6 +78,9 @@
#djangoForumThreadPostDetail {
width: 20%;
}
+.djangoForumPagination {
+ display: inline;
+}
--></style>
<body>
<div id='djangoForumBody'>
Index: forum/templates/forum/thread_list.html
===================================================================
--- forum/templates/forum/thread_list.html (revision 24)
+++ forum/templates/forum/thread_list.html (working copy)
@@ -1,4 +1,5 @@
{% extends "forum_base.html" %}
+{% load i18n %}
{% block title %}{{ forum.title }}{% endblock %}
@@ -43,7 +44,7 @@
<th style='width: 220px;'>Last Post</th>
</tr>
-{% for t in threads %}
+{% for t in thread_list %}
<tr>
<td>{% if t.sticky %}Sticky {% endif %}<a href='{{ t.get_absolute_url }}'>{{ t.title|escape }}</a>{% if t.closed %} (Closed){% endif %}</td>
<td style='width: 50px;'>{{ t.posts }}</td>
@@ -55,6 +56,16 @@
{% endfor %}
</table>
+{% if is_paginated %}
+<ul>
+ <li class="djangoForumPagination"><a href="?page=1">{% trans "First" %}</a></li>
+{% for page_number in paginator.page_range %}
+ <li class="djangoForumPagination"><a href="?page={{ page_number }}">{{ page_number }}</a></li>
+{% endfor %}
+ <li class="djangoForumPagination"><a href="?page={{ paginator.num_pages }}">{% trans "Last" %}</a></li>
+</ul>
+{% endif %}
+
<h2>Create a Thread</h2>
{% if user.is_authenticated %}
<form method='post' action='new/'>
Index: forum/templates/forum/thread.html
===================================================================
--- forum/templates/forum/thread.html (revision 24)
+++ forum/templates/forum/thread.html (working copy)
@@ -10,7 +10,7 @@
<table id='djangoForumThreadPosts'>
{% load markup %}
-{% for post in posts %}
+{% for post in post_list %}
<tr>
<th class='djangoForumThreadPostDetail' id='post{{ post.id }}'>{{ post.time|timesince }} ago<br />
@@ -20,6 +20,16 @@
</table>
+{% if is_paginated %}
+<ul>
+ <li class="djangoForumPagination"><a href="?page=1">{% trans "First" %}</a></li>
+{% for page_number in paginator.page_range %}
+ <li class="djangoForumPagination"><a href="?page={{ page_number }}">{{ page_number }}</a></li>
+{% endfor %}
+ <li class="djangoForumPagination"><a href="?page={{ paginator.num_pages }}">{% trans "Last" %}</a></li>
+</ul>
+{% endif %}
+
<h2><a href="{% url forum_subscriptions %}">Update Subscriptions</a></h2>
<h2>Post a Reply</h2>
{% if thread.closed %}
Powered by
Google Project Hosting