widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #10991
[Merge] lp:~widelands-dev/widelands-website/pagination into lp:widelands-website
kaputtnik has proposed merging lp:~widelands-dev/widelands-website/pagination into lp:widelands-website.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1710577 in Widelands Website: "Page navigator doesn't fit for long pages"
https://bugs.launchpad.net/widelands-website/+bug/1710577
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/pagination/+merge/329350
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.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/pagination into lp:widelands-website.
=== added file 'mainpage/templatetags/get_model_name.py'
--- mainpage/templatetags/get_model_name.py 1970-01-01 00:00:00 +0000
+++ mainpage/templatetags/get_model_name.py 2017-08-22 06:26:29 +0000
@@ -0,0 +1,8 @@
+from django import template
+
+register = template.Library()
+
+@register.filter
+def get_model_name(object):
+ """Returns the name of an objects model"""
+ return object.__class__.__name__
\ No newline at end of file
=== modified file 'media/css/base.css'
--- media/css/base.css 2017-08-07 16:48:51 +0000
+++ media/css/base.css 2017-08-22 06:26:29 +0000
@@ -49,10 +49,6 @@
color: #181;
}
-.breadCrumb{
- margin-bottom: 10px;
-}
-
/* We put this after a:hover */
/* to prevend the hover style */
/* for this link */
@@ -422,8 +418,7 @@
-khtml-border-radius: 4px;
border-radius: 4px;
border: 1px solid black;
- padding: 15px;
- padding-bottom: 30px;
+ padding: 1em 1em 2em 1em;
margin-bottom: 20px;
box-shadow: 4px 4px 4px 0px rgba(0, 0, 0, 0.7);
}
@@ -451,4 +446,23 @@
clear: left;
}
-
+div.blogEntry .breadCrumb{
+ margin-bottom: 1em;
+}
+
+div.blogEntry .posRight{
+ margin-bottom: 1em;
+}
+
+/* Pagination */
+
+.pagination .current.page{
+ font-weight: bold;
+ font-size: large;
+ color: #C8BE93;
+ vertical-align: bottom;
+}
+
+.pagination .summary{
+ margin-right: 1em;
+}
=== modified file 'media/css/forum.css'
--- media/css/forum.css 2017-08-07 16:48:51 +0000
+++ media/css/forum.css 2017-08-22 06:26:29 +0000
@@ -14,6 +14,7 @@
border-collapse: collapse;
table-layout: fixed;
width: 100%;
+ margin-bottom: 1em;
}
.forum tr {
=== modified file 'pybb/util.py'
--- pybb/util.py 2017-01-23 13:01:31 +0000
+++ pybb/util.py 2017-08-22 06:26:29 +0000
@@ -173,7 +173,6 @@
"""Quote message using selected markup."""
text = '*' + user.username + ' wrote:*\n\n' + text
- # if markup == 'markdown':
if markup == 'markdown':
# Inserting a space after ">" will not change the generated HTML,
# but it will unbreak certain constructs like '>:-))'.
@@ -205,51 +204,6 @@
return wrapper
-def paginate(items, request, per_page, total_count=None):
- try:
- page_number = int(request.GET.get('page', 1))
- except ValueError:
- page_number = 1
-
- paginator = Paginator(items, per_page)
- if total_count:
- paginator._count = total_count
-
- try:
- page = paginator.page(page_number)
- except (EmptyPage, InvalidPage):
- page = paginator.page(1)
-
- if page.has_previous:
- get = request.GET.copy()
- get['page'] = page.number - 1
- page.previous_link = '?%s' % get.urlencode()
- else:
- page.previous_link = None
-
- if page.has_next:
- get = request.GET.copy()
- get['page'] = page.number + 1
- page.next_link = '?%s' % get.urlencode()
- else:
- page.next_link = None
-
- #import pdb; pdb.set_trace()
-
- return page, paginator
-
-
-# TODO(Franku): This function is never used AFAIK
-# 'django_language' isn't available since django 1.8
-def set_language(request, language):
- """Change the language of session of authenticated user."""
- if language and check_for_language(language):
- if hasattr(request, 'session'):
- request.session['django_language'] = language
- else:
- response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language)
-
-
def unescape(text):
"""Do reverse escaping."""
=== modified file 'pybb/views.py'
--- pybb/views.py 2017-02-24 19:15:17 +0000
+++ pybb/views.py 2017-08-22 06:26:29 +0000
@@ -12,7 +12,7 @@
from django.utils import translation
from django.shortcuts import render
-from pybb.util import render_to, paged, build_form, quote_text, paginate, set_language, ajax, urlize
+from pybb.util import render_to, paged, build_form, quote_text, ajax, urlize
from pybb.models import Category, Forum, Topic, Post, PrivateMessage, Attachment,\
MARKUP_CHOICES
from pybb.forms import AddPostForm, EditPostForm, UserSearchForm
@@ -69,13 +69,11 @@
topics = forum.topics.order_by(
'-sticky', '-updated').exclude(posts__hidden=True).select_related()
- page, paginator = paginate(topics, request, pybb_settings.FORUM_PAGE_SIZE)
return {'forum': forum,
- 'topics': page.object_list,
+ 'topics': topics,
'quick': quick,
- 'page': page,
- 'paginator': paginator,
+ 'page_size': pybb_settings.FORUM_PAGE_SIZE,
}
show_forum = render_to('pybb/forum.html')(show_forum_ctx)
@@ -108,8 +106,6 @@
request.user in topic.subscribers.all())
posts = topic.posts.exclude(hidden=True).select_related()
- page, paginator = paginate(posts, request, pybb_settings.TOPIC_PAGE_SIZE,
- total_count=topic.post_count)
# TODO: fetch profiles
# profiles = Profile.objects.filter(user__pk__in=
@@ -119,7 +115,7 @@
# for post in page.object_list:
# post.user.pybb_profile = profiles[post.user.id]
- load_related(page.object_list, Attachment.objects.all(), 'post')
+ load_related(posts, Attachment.objects.all(), 'post')
return {'topic': topic,
'last_post': last_post,
@@ -127,9 +123,8 @@
'form': form,
'moderator': moderator,
'subscribed': subscribed,
- 'posts': page.object_list,
- 'page': page,
- 'paginator': paginator,
+ 'posts': posts,
+ 'page_size': pybb_settings.TOPIC_PAGE_SIZE,
'form_url': reverse('pybb_add_post', args=[topic.id]),
}
show_topic = render_to('pybb/topic.html')(show_topic_ctx)
=== modified file 'settings.py'
--- settings.py 2017-01-21 12:39:23 +0000
+++ settings.py 2017-08-22 06:26:29 +0000
@@ -306,6 +306,13 @@
BLEACH_ALLOWED_ATTRIBUTES = {'img': ['src', 'alt'], 'a': [
'href'], 'td': ['align'], '*': ['class', 'id', 'title']}
+################################
+# Pagination settings #
+# for linaro-django-pagination #
+################################
+PAGINATION_DEFAULT_WINDOW = 2
+
+
try:
from local_settings import *
except ImportError:
=== modified file 'templates/news/category_posts.html'
--- templates/news/category_posts.html 2016-11-21 17:45:28 +0000
+++ templates/news/category_posts.html 2017-08-22 06:26:29 +0000
@@ -22,14 +22,14 @@
</div>
<div class="blogEntry">
<div class="center">
- {% autopaginate post_list 20 %}
- {% paginate %}
+ {% autopaginate post_list 20 as object_list %}
+ {% paginate using "pagination/pagination_mod.html" %}
</div>
<table width="100%">
<th align="left">Title</th>
<th>Posted at</th>
<th>Comments</th>
- {% for post in post_list %}
+ {% for post in object_list %}
{% get_comment_count for post as ccount %}
<tr>
<td><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></td>
=== modified file 'templates/news/inlines/posts_table.html'
--- templates/news/inlines/posts_table.html 2016-11-18 23:50:23 +0000
+++ templates/news/inlines/posts_table.html 2017-08-22 06:26:29 +0000
@@ -9,7 +9,7 @@
<div class="blogEntry">
<div class="center">
{% autopaginate object_list 20 %}
- {% paginate %}
+ {% paginate using "pagination/pagination_mod.html" %}
</div>
<table width="100%">
<caption></caption>
=== modified file 'templates/notification/notice_settings.html'
--- templates/notification/notice_settings.html 2017-04-29 18:53:06 +0000
+++ templates/notification/notice_settings.html 2017-08-22 06:26:29 +0000
@@ -1,7 +1,6 @@
{% extends "notification/base.html" %}
{% load humanize i18n %}
-{% load pagination_tags %}
{% load custom_date %}
{% block title %}
=== added directory 'templates/pagination'
=== added file 'templates/pagination/pagination_mod.html'
--- templates/pagination/pagination_mod.html 1970-01-01 00:00:00 +0000
+++ templates/pagination/pagination_mod.html 2017-08-22 06:26:29 +0000
@@ -0,0 +1,32 @@
+{% extends "pagination/pagination.html" %}
+{% comment %}
+This template overrides one block of the shipped template of
+linaro-django-pagination to get a nice prequel to the
+pagination: (x - y of z modelsname).
+Involved: Custom filter in mainpage.templatetags.get_model_name
+{% endcomment %}
+
+{% load i18n %}
+{% load get_model_name %}
+ {% block previouslink %}
+ <span class="summary">
+ <strong>{{ page_obj.start_index }}</strong> —
+ <strong>{{ page_obj.end_index }}</strong> {% trans "of" %}
+ <strong>{{ paginator.count }}</strong>
+ {{ object_list.0 | get_model_name }}{{ paginator.count|pluralize }}</span>
+ {% if page_obj.has_previous %}
+ {% if disable_link_for_first_page and page_obj.previous_page_number == 1 %}
+ <a href="{{ request.path }}
+ {% if getvars %}
+ ?{{ getvars|slice:"1:" }}
+ {% endif %}
+ " class="prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</a>
+ {% else %}
+ <a href="?page{{ page_suffix }}={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</a>
+ {% endif %}
+ {% else %}
+ {% if display_disabled_previous_link %}
+ <span class="disabled prev">{{ previous_link_decorator|safe }}{% trans "previous" %}</span>
+ {% endif %}
+ {% endif %}
+ {% endblock previouslink %}
=== modified file 'templates/pybb/forum.html'
--- templates/pybb/forum.html 2016-10-29 20:47:11 +0000
+++ templates/pybb/forum.html 2017-08-22 06:26:29 +0000
@@ -4,6 +4,7 @@
{% load humanize %}
{% load wlprofile_extras %}
{% load custom_date %}
+{% load pagination_tags %}
{% block title %}
{{ forum.name }} - {{ block.super }}
@@ -19,16 +20,17 @@
<h1>Forum: {{ forum }}</h1>
<div class="blogEntry">
+ <div class="breadCrumb">
<a href="{% url 'pybb_index' %}">Forums</a> »
{% pybb_link forum.category %} »
{{ forum }}
- <br /><br />
+ </div>
<a class="button posRight" href="{% url 'pybb_add_topic' forum.id %}">
<img src="{{ MEDIA_URL }}forum/img/new_topic.png" alt ="{% trans "New Topic" %}" class="middle" />
<span class="middle">{% trans "New Topic" %}</span>
</a>
- {% pybb_pagination _('Topics') %}
- <br /><br />
+ {% autopaginate topics page_size as object_list %}
+ {% paginate using "pagination/pagination_mod.html" %}
<table class="forum">
<thead>
@@ -40,7 +42,7 @@
</tr>
</thead>
<tbody>
- {% for topic in topics %}
+ {% for topic in object_list %}
<tr class="{% cycle 'odd' 'even' %}">
<td class="forumIcon center">
{% if topic|pybb_has_unreads:user %}
@@ -69,14 +71,11 @@
{% endfor %}
</tbody>
</table>
-
- <br />
<a class="button posRight" href="{% url 'pybb_add_topic' forum.id %}">
<img src="{{ MEDIA_URL }}forum/img/new_topic.png" alt ="{% trans "New Topic" %}" class="middle" />
<span class="middle">{% trans "New Topic" %}</span>
</a>
- {% pybb_pagination _('Topics') %}
- <br />
+ {% paginate %}
</div>
<div class="center green">
=== modified file 'templates/pybb/topic.html'
--- templates/pybb/topic.html 2016-10-29 20:47:11 +0000
+++ templates/pybb/topic.html 2017-08-22 06:26:29 +0000
@@ -5,6 +5,7 @@
{% load wiki_extras %}
{% load wlprofile_extras %}
{% load custom_date %}
+{% load pagination_tags %}
{% block title %}
{{ topic.name }} - {{ topic.forum.name }} - {{ block.super }}
@@ -19,11 +20,13 @@
{% block content %}
<h1>Topic: {{ topic }} </h1>
<div class="blogEntry">
+ <div class="breadCrumb">
<a href="{% url 'pybb_index' %}">Forums</a> »
{% pybb_link topic.forum.category %} »
<a href="{{ topic.forum.get_absolute_url }}">{{ topic.forum.name }}</a> »
{{ topic }}
- <br /><br />
+ </div>
+
<div class="posRight">
{% if moderator %}
{% if topic.sticky %}
@@ -67,8 +70,8 @@
</a>
{% endif %}
</div>
- {% pybb_pagination _('Posts') %}
- <br /><br />
+ {% autopaginate posts page_size as object_list %}
+ {% paginate using "pagination/pagination_mod.html" %}
{% if first_post %}
{% ifnotequal first_post posts.0 %}
@@ -156,7 +159,7 @@
<table class="forum">
<tbody>
- {% for post in posts %}
+ {% for post in object_list %}
<tr class="{% cycle 'odd' 'even' %}">
<td class="author">
{{ post.user|user_link }}<br />
@@ -228,10 +231,13 @@
{% endif %}
</td>
</tr>
+ {% if not forloop.last %}
+ {# no spacer at end of table #}
<tr class="spacer">
<td></td>
<td></td>
</tr>
+ {% endif %}
{% endfor %}
</tbody>
</table>
@@ -279,8 +285,7 @@
</a>
{% endif %}
</div>
- {% pybb_pagination _('Posts') %}
- <br />
+ {% paginate %}
</div>
{% if user.is_authenticated %}
=== modified file 'templates/wiki/recentchanges.html'
--- templates/wiki/recentchanges.html 2016-03-02 21:02:38 +0000
+++ templates/wiki/recentchanges.html 2017-08-22 06:26:29 +0000
@@ -11,10 +11,10 @@
{% block content %}
<h1>Wiki: {% trans "Recent Changes" %}</h1>
<div class="blogEntry">
-{% autopaginate changes %}
-{% paginate %}
+{% autopaginate changes as object_list %}
+{% paginate using "pagination/pagination_mod.html" %}
<br />
-{% for change in changes %}
+{% for change in object_list %}
{% ifchanged change.modified.date %}
{% if not forloop.first %}
</table>
=== modified file 'templates/wlmaps/index.html'
--- templates/wlmaps/index.html 2016-05-18 19:31:46 +0000
+++ templates/wlmaps/index.html 2017-08-22 06:26:29 +0000
@@ -16,11 +16,11 @@
<p>
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.
</p>
- {% autopaginate maps maps_per_page %}
- {% paginate %}
+ {% autopaginate maps maps_per_page as object_list %}
+ {% paginate using "pagination/pagination_mod.html" %}
<br />
<table class="maps">
- {% for map in maps %}
+ {% for map in object_list %}
<tr class="{% cycle "odd" "even" %}">
<td class="first-column"><a href="{{ map.get_absolute_url }}"><img class="minimap" src="{{ MEDIA_URL }}{{ map.minimap.url }}" alt="{{ map.name }}" /></a></td>
<td>
Follow ups