Merge lp:~widelands-dev/widelands-website/pagination into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 469
Proposed branch: lp:~widelands-dev/widelands-website/pagination
Merge into: lp:widelands-website
Diff against target: 480 lines (+104/-90)
15 files modified
mainpage/templatetags/get_model_name.py (+8/-0)
media/css/base.css (+21/-7)
media/css/forum.css (+1/-0)
pip_requirements.txt (+1/-1)
pybb/util.py (+0/-46)
pybb/views.py (+6/-11)
settings.py (+7/-0)
templates/news/category_posts.html (+3/-3)
templates/news/inlines/posts_table.html (+1/-1)
templates/notification/notice_settings.html (+0/-1)
templates/pagination/pagination_mod.html (+32/-0)
templates/pybb/forum.html (+7/-8)
templates/pybb/topic.html (+11/-6)
templates/wiki/recentchanges.html (+3/-3)
templates/wlmaps/index.html (+3/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/pagination
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+329350@code.launchpad.net

Description of the change

Replace pybb pagination with linaro-django-pagination which is used at many other places, e.g. News and Maps. There are two sorts of pagination available:

1. "<< previous 1 2 ... 3 4 5 6 7 ... next >>"
2. "51 of 60 Topics << previous 1 2 ... 3 4 5 6 7 ... next >>"

- Removed the pagination code from pybb
- added partly overwritten template for the pagination
- added a function to get a models name in the pagination, so it shows "1 - 10 of [Topics/Posts/Maps]"
- the actual page is shown a bit emphasized
- use overwritten template (2) at the top of forum and topic
- use default template (1) at the bottom
- removed some html <br>-tags and position the contents with css
- removed some unused code from pybb.util
- Changed numbers of items to the left and to the right of the current page to display from 4 (default) to 2. See: https://pythonhosted.org/linaro-django-pagination/usage.html#optional-settings

I have tested this changes locally also with pybb attachments enabled and i found no issues.

Gun: I have fiddled a lot to reduce the space below the pagination, don't know if i got it. Especially at the bottom is a big space left if there is no pagination shown.

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

I am getting 2 warning during pip install -r pip_requirements.txt. Feel free to have a look in a separate branch.

  Cloning git://github.com/zyga/django-pagination.git (to 86caf150984733eb5a0bb07af26cd8fc0a8d8496) to /home/bratzbert/widelands-website/wlwebsite/src/linaro-django-pagination
  Could not find a tag or branch '86caf150984733eb5a0bb07af26cd8fc0a8d8496', assuming commit.

And unrelated to this particular branch:
  Cloning git://github.com/kerin/django-sphinx.git (to 1c5ef8abcf86f9a9458f763ceb9e5d882247ea37) to /home/bratzbert/widelands-website/wlwebsite/src/django-sphinx
  Could not find a tag or branch '1c5ef8abcf86f9a9458f763ceb9e5d882247ea37', assuming commit.

I wanted to do a bit of testing, but it would take too long go create content, so I'll just assume that you have tested it well. Code LGTM.

review: Approve
474. By kaputtnik

fixed pip_requirements.txt regarding linaro-django-pagination

Revision history for this message
kaputtnik (franku) wrote :

Thanks for taking the time for installing the website :-)

The warnings are harmless, but i fixed the one regarding linaro-django-pagination. django-sphinx is used for searching and i am working on branch wich replaces django-sphinx, so i leave this.

I have applied the changes to the alpha site for testing: http://alpha.widelands.org/forum/forum/1/

You may have to reload the page by hitting F5 (or CTRL/SHIFT F5) to get a fresh copy of the css.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Looking good - ship it :)

Revision history for this message
kaputtnik (franku) wrote :

Thanks :-) merged and deployed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'mainpage/templatetags/get_model_name.py'
2--- mainpage/templatetags/get_model_name.py 1970-01-01 00:00:00 +0000
3+++ mainpage/templatetags/get_model_name.py 2017-08-25 07:01:20 +0000
4@@ -0,0 +1,8 @@
5+from django import template
6+
7+register = template.Library()
8+
9+@register.filter
10+def get_model_name(object):
11+ """Returns the name of an objects model"""
12+ return object.__class__.__name__
13\ No newline at end of file
14
15=== modified file 'media/css/base.css'
16--- media/css/base.css 2017-08-07 16:48:51 +0000
17+++ media/css/base.css 2017-08-25 07:01:20 +0000
18@@ -49,10 +49,6 @@
19 color: #181;
20 }
21
22-.breadCrumb{
23- margin-bottom: 10px;
24-}
25-
26 /* We put this after a:hover */
27 /* to prevend the hover style */
28 /* for this link */
29@@ -422,8 +418,7 @@
30 -khtml-border-radius: 4px;
31 border-radius: 4px;
32 border: 1px solid black;
33- padding: 15px;
34- padding-bottom: 30px;
35+ padding: 1em 1em 2em 1em;
36 margin-bottom: 20px;
37 box-shadow: 4px 4px 4px 0px rgba(0, 0, 0, 0.7);
38 }
39@@ -451,4 +446,23 @@
40 clear: left;
41 }
42
43-
44+div.blogEntry .breadCrumb{
45+ margin-bottom: 1em;
46+}
47+
48+div.blogEntry .posRight{
49+ margin-bottom: 1em;
50+}
51+
52+/* Pagination */
53+
54+.pagination .current.page{
55+ font-weight: bold;
56+ font-size: large;
57+ color: #C8BE93;
58+ vertical-align: bottom;
59+}
60+
61+.pagination .summary{
62+ margin-right: 1em;
63+}
64
65=== modified file 'media/css/forum.css'
66--- media/css/forum.css 2017-08-07 16:48:51 +0000
67+++ media/css/forum.css 2017-08-25 07:01:20 +0000
68@@ -14,6 +14,7 @@
69 border-collapse: collapse;
70 table-layout: fixed;
71 width: 100%;
72+ margin-bottom: 1em;
73 }
74
75 .forum tr {
76
77=== modified file 'pip_requirements.txt'
78--- pip_requirements.txt 2017-06-23 21:34:47 +0000
79+++ pip_requirements.txt 2017-08-25 07:01:20 +0000
80@@ -5,7 +5,7 @@
81 django-contrib-comments==1.8.0
82 django-messages==0.5.3
83 django-nocaptcha-recaptcha==0.0.19
84--e git://github.com/zyga/django-pagination.git@86caf150984733eb5a0bb07af26cd8fc0a8d8496#egg=linaro_django_pagination
85+-e git://github.com/zyga/django-pagination.git#egg=linaro_django_pagination
86 django-registration==2.2
87 django-tagging==0.4.5
88 gunicorn==19.7.1
89
90=== modified file 'pybb/util.py'
91--- pybb/util.py 2017-01-23 13:01:31 +0000
92+++ pybb/util.py 2017-08-25 07:01:20 +0000
93@@ -173,7 +173,6 @@
94 """Quote message using selected markup."""
95 text = '*' + user.username + ' wrote:*\n\n' + text
96
97- # if markup == 'markdown':
98 if markup == 'markdown':
99 # Inserting a space after ">" will not change the generated HTML,
100 # but it will unbreak certain constructs like '>:-))'.
101@@ -205,51 +204,6 @@
102 return wrapper
103
104
105-def paginate(items, request, per_page, total_count=None):
106- try:
107- page_number = int(request.GET.get('page', 1))
108- except ValueError:
109- page_number = 1
110-
111- paginator = Paginator(items, per_page)
112- if total_count:
113- paginator._count = total_count
114-
115- try:
116- page = paginator.page(page_number)
117- except (EmptyPage, InvalidPage):
118- page = paginator.page(1)
119-
120- if page.has_previous:
121- get = request.GET.copy()
122- get['page'] = page.number - 1
123- page.previous_link = '?%s' % get.urlencode()
124- else:
125- page.previous_link = None
126-
127- if page.has_next:
128- get = request.GET.copy()
129- get['page'] = page.number + 1
130- page.next_link = '?%s' % get.urlencode()
131- else:
132- page.next_link = None
133-
134- #import pdb; pdb.set_trace()
135-
136- return page, paginator
137-
138-
139-# TODO(Franku): This function is never used AFAIK
140-# 'django_language' isn't available since django 1.8
141-def set_language(request, language):
142- """Change the language of session of authenticated user."""
143- if language and check_for_language(language):
144- if hasattr(request, 'session'):
145- request.session['django_language'] = language
146- else:
147- response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language)
148-
149-
150 def unescape(text):
151 """Do reverse escaping."""
152
153
154=== modified file 'pybb/views.py'
155--- pybb/views.py 2017-02-24 19:15:17 +0000
156+++ pybb/views.py 2017-08-25 07:01:20 +0000
157@@ -12,7 +12,7 @@
158 from django.utils import translation
159 from django.shortcuts import render
160
161-from pybb.util import render_to, paged, build_form, quote_text, paginate, set_language, ajax, urlize
162+from pybb.util import render_to, paged, build_form, quote_text, ajax, urlize
163 from pybb.models import Category, Forum, Topic, Post, PrivateMessage, Attachment,\
164 MARKUP_CHOICES
165 from pybb.forms import AddPostForm, EditPostForm, UserSearchForm
166@@ -69,13 +69,11 @@
167
168 topics = forum.topics.order_by(
169 '-sticky', '-updated').exclude(posts__hidden=True).select_related()
170- page, paginator = paginate(topics, request, pybb_settings.FORUM_PAGE_SIZE)
171
172 return {'forum': forum,
173- 'topics': page.object_list,
174+ 'topics': topics,
175 'quick': quick,
176- 'page': page,
177- 'paginator': paginator,
178+ 'page_size': pybb_settings.FORUM_PAGE_SIZE,
179 }
180 show_forum = render_to('pybb/forum.html')(show_forum_ctx)
181
182@@ -108,8 +106,6 @@
183 request.user in topic.subscribers.all())
184
185 posts = topic.posts.exclude(hidden=True).select_related()
186- page, paginator = paginate(posts, request, pybb_settings.TOPIC_PAGE_SIZE,
187- total_count=topic.post_count)
188
189 # TODO: fetch profiles
190 # profiles = Profile.objects.filter(user__pk__in=
191@@ -119,7 +115,7 @@
192 # for post in page.object_list:
193 # post.user.pybb_profile = profiles[post.user.id]
194
195- load_related(page.object_list, Attachment.objects.all(), 'post')
196+ load_related(posts, Attachment.objects.all(), 'post')
197
198 return {'topic': topic,
199 'last_post': last_post,
200@@ -127,9 +123,8 @@
201 'form': form,
202 'moderator': moderator,
203 'subscribed': subscribed,
204- 'posts': page.object_list,
205- 'page': page,
206- 'paginator': paginator,
207+ 'posts': posts,
208+ 'page_size': pybb_settings.TOPIC_PAGE_SIZE,
209 'form_url': reverse('pybb_add_post', args=[topic.id]),
210 }
211 show_topic = render_to('pybb/topic.html')(show_topic_ctx)
212
213=== modified file 'settings.py'
214--- settings.py 2017-01-21 12:39:23 +0000
215+++ settings.py 2017-08-25 07:01:20 +0000
216@@ -306,6 +306,13 @@
217 BLEACH_ALLOWED_ATTRIBUTES = {'img': ['src', 'alt'], 'a': [
218 'href'], 'td': ['align'], '*': ['class', 'id', 'title']}
219
220+################################
221+# Pagination settings #
222+# for linaro-django-pagination #
223+################################
224+PAGINATION_DEFAULT_WINDOW = 2
225+
226+
227 try:
228 from local_settings import *
229 except ImportError:
230
231=== modified file 'templates/news/category_posts.html'
232--- templates/news/category_posts.html 2016-11-21 17:45:28 +0000
233+++ templates/news/category_posts.html 2017-08-25 07:01:20 +0000
234@@ -22,14 +22,14 @@
235 </div>
236 <div class="blogEntry">
237 <div class="center">
238- {% autopaginate post_list 20 %}
239- {% paginate %}
240+ {% autopaginate post_list 20 as object_list %}
241+ {% paginate using "pagination/pagination_mod.html" %}
242 </div>
243 <table width="100%">
244 <th align="left">Title</th>
245 <th>Posted at</th>
246 <th>Comments</th>
247- {% for post in post_list %}
248+ {% for post in object_list %}
249 {% get_comment_count for post as ccount %}
250 <tr>
251 <td><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></td>
252
253=== modified file 'templates/news/inlines/posts_table.html'
254--- templates/news/inlines/posts_table.html 2016-11-18 23:50:23 +0000
255+++ templates/news/inlines/posts_table.html 2017-08-25 07:01:20 +0000
256@@ -9,7 +9,7 @@
257 <div class="blogEntry">
258 <div class="center">
259 {% autopaginate object_list 20 %}
260- {% paginate %}
261+ {% paginate using "pagination/pagination_mod.html" %}
262 </div>
263 <table width="100%">
264 <caption></caption>
265
266=== modified file 'templates/notification/notice_settings.html'
267--- templates/notification/notice_settings.html 2017-04-29 18:53:06 +0000
268+++ templates/notification/notice_settings.html 2017-08-25 07:01:20 +0000
269@@ -1,7 +1,6 @@
270 {% extends "notification/base.html" %}
271
272 {% load humanize i18n %}
273-{% load pagination_tags %}
274 {% load custom_date %}
275
276 {% block title %}
277
278=== added directory 'templates/pagination'
279=== added file 'templates/pagination/pagination_mod.html'
280--- templates/pagination/pagination_mod.html 1970-01-01 00:00:00 +0000
281+++ templates/pagination/pagination_mod.html 2017-08-25 07:01:20 +0000
282@@ -0,0 +1,32 @@
283+{% extends "pagination/pagination.html" %}
284+{% comment %}
285+This template overrides one block of the shipped template of
286+linaro-django-pagination to get a nice prequel to the
287+pagination: (x - y of z modelsname).
288+Involved: Custom filter in mainpage.templatetags.get_model_name
289+{% endcomment %}
290+
291+{% load i18n %}
292+{% load get_model_name %}
293+ {% block previouslink %}
294+ <span class="summary">
295+ <strong>{{ page_obj.start_index }}</strong> &mdash;
296+ <strong>{{ page_obj.end_index }}</strong> {% trans "of" %}
297+ <strong>{{ paginator.count }}</strong>
298+ {{ object_list.0 | get_model_name }}{{ paginator.count|pluralize }}</span>
299+ {% if page_obj.has_previous %}
300+ {% if disable_link_for_first_page and page_obj.previous_page_number == 1 %}
301+ <a href="{{ request.path }}
302+ {% if getvars %}
303+ ?{{ getvars|slice:"1:" }}
304+ {% endif %}
305+ " class="prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</a>
306+ {% else %}
307+ <a href="?page{{ page_suffix }}={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</a>
308+ {% endif %}
309+ {% else %}
310+ {% if display_disabled_previous_link %}
311+ <span class="disabled prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</span>
312+ {% endif %}
313+ {% endif %}
314+ {% endblock previouslink %}
315
316=== modified file 'templates/pybb/forum.html'
317--- templates/pybb/forum.html 2016-10-29 20:47:11 +0000
318+++ templates/pybb/forum.html 2017-08-25 07:01:20 +0000
319@@ -4,6 +4,7 @@
320 {% load humanize %}
321 {% load wlprofile_extras %}
322 {% load custom_date %}
323+{% load pagination_tags %}
324
325 {% block title %}
326 {{ forum.name }} - {{ block.super }}
327@@ -19,16 +20,17 @@
328 <h1>Forum: {{ forum }}</h1>
329
330 <div class="blogEntry">
331+ <div class="breadCrumb">
332 <a href="{% url 'pybb_index' %}">Forums</a> &#187;
333 {% pybb_link forum.category %} &#187;
334 {{ forum }}
335- <br /><br />
336+ </div>
337 <a class="button posRight" href="{% url 'pybb_add_topic' forum.id %}">
338 <img src="{{ MEDIA_URL }}forum/img/new_topic.png" alt ="{% trans "New Topic" %}" class="middle" />
339 <span class="middle">{% trans "New Topic" %}</span>
340 </a>
341- {% pybb_pagination _('Topics') %}
342- <br /><br />
343+ {% autopaginate topics page_size as object_list %}
344+ {% paginate using "pagination/pagination_mod.html" %}
345
346 <table class="forum">
347 <thead>
348@@ -40,7 +42,7 @@
349 </tr>
350 </thead>
351 <tbody>
352- {% for topic in topics %}
353+ {% for topic in object_list %}
354 <tr class="{% cycle 'odd' 'even' %}">
355 <td class="forumIcon center">
356 {% if topic|pybb_has_unreads:user %}
357@@ -69,14 +71,11 @@
358 {% endfor %}
359 </tbody>
360 </table>
361-
362- <br />
363 <a class="button posRight" href="{% url 'pybb_add_topic' forum.id %}">
364 <img src="{{ MEDIA_URL }}forum/img/new_topic.png" alt ="{% trans "New Topic" %}" class="middle" />
365 <span class="middle">{% trans "New Topic" %}</span>
366 </a>
367- {% pybb_pagination _('Topics') %}
368- <br />
369+ {% paginate %}
370 </div>
371
372 <div class="center green">
373
374=== modified file 'templates/pybb/topic.html'
375--- templates/pybb/topic.html 2016-10-29 20:47:11 +0000
376+++ templates/pybb/topic.html 2017-08-25 07:01:20 +0000
377@@ -5,6 +5,7 @@
378 {% load wiki_extras %}
379 {% load wlprofile_extras %}
380 {% load custom_date %}
381+{% load pagination_tags %}
382
383 {% block title %}
384 {{ topic.name }} - {{ topic.forum.name }} - {{ block.super }}
385@@ -19,11 +20,13 @@
386 {% block content %}
387 <h1>Topic: {{ topic }} </h1>
388 <div class="blogEntry">
389+ <div class="breadCrumb">
390 <a href="{% url 'pybb_index' %}">Forums</a> &#187;
391 {% pybb_link topic.forum.category %} &#187;
392 <a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum.name }}</a> &#187;
393 {{ topic }}
394- <br /><br />
395+ </div>
396+
397 <div class="posRight">
398 {% if moderator %}
399 {% if topic.sticky %}
400@@ -67,8 +70,8 @@
401 </a>
402 {% endif %}
403 </div>
404- {% pybb_pagination _('Posts') %}
405- <br /><br />
406+ {% autopaginate posts page_size as object_list %}
407+ {% paginate using "pagination/pagination_mod.html" %}
408
409 {% if first_post %}
410 {% ifnotequal first_post posts.0 %}
411@@ -156,7 +159,7 @@
412
413 <table class="forum">
414 <tbody>
415- {% for post in posts %}
416+ {% for post in object_list %}
417 <tr class="{% cycle 'odd' 'even' %}">
418 <td class="author">
419 {{ post.user|user_link }}<br />
420@@ -228,10 +231,13 @@
421 {% endif %}
422 </td>
423 </tr>
424+ {% if not forloop.last %}
425+ {# no spacer at end of table #}
426 <tr class="spacer">
427 <td></td>
428 <td></td>
429 </tr>
430+ {% endif %}
431 {% endfor %}
432 </tbody>
433 </table>
434@@ -279,8 +285,7 @@
435 </a>
436 {% endif %}
437 </div>
438- {% pybb_pagination _('Posts') %}
439- <br />
440+ {% paginate %}
441 </div>
442
443 {% if user.is_authenticated %}
444
445=== modified file 'templates/wiki/recentchanges.html'
446--- templates/wiki/recentchanges.html 2016-03-02 21:02:38 +0000
447+++ templates/wiki/recentchanges.html 2017-08-25 07:01:20 +0000
448@@ -11,10 +11,10 @@
449 {% block content %}
450 <h1>Wiki: {% trans "Recent Changes" %}</h1>
451 <div class="blogEntry">
452-{% autopaginate changes %}
453-{% paginate %}
454+{% autopaginate changes as object_list %}
455+{% paginate using "pagination/pagination_mod.html" %}
456 <br />
457-{% for change in changes %}
458+{% for change in object_list %}
459 {% ifchanged change.modified.date %}
460 {% if not forloop.first %}
461 </table>
462
463=== modified file 'templates/wlmaps/index.html'
464--- templates/wlmaps/index.html 2016-05-18 19:31:46 +0000
465+++ templates/wlmaps/index.html 2017-08-25 07:01:20 +0000
466@@ -16,11 +16,11 @@
467 <p>
468 The map files have to be placed in the Widelands map directory to be found by the game. Check the <a href="/wiki/Technical%20FAQ/#where_are_my_maps_and_savegames_stored">Technical FAQ</a> to find the map directory.
469 </p>
470- {% autopaginate maps maps_per_page %}
471- {% paginate %}
472+ {% autopaginate maps maps_per_page as object_list %}
473+ {% paginate using "pagination/pagination_mod.html" %}
474 <br />
475 <table class="maps">
476- {% for map in maps %}
477+ {% for map in object_list %}
478 <tr class="{% cycle "odd" "even" %}">
479 <td class="first-column"><a href="{{ map.get_absolute_url }}"><img class="minimap" src="{{ MEDIA_URL }}{{ map.minimap.url }}" alt="{{ map.name }}" /></a></td>
480 <td>

Subscribers

People subscribed via source and target branches