Browse Source

Apply sorting on subsequent pages

Modified render_pagination macro by adding two optional arguemts sort_by and asc.
If sorted is set as a string, sort_by and order_by (asc if asc set to True,
desc otherwise) are injected to the page links.
This helps to keep the sorting of the members in memberlist if the users wants to see
e.g. the second page of users with most comments
Andreas Groß 8 years ago
parent
commit
3d976b159a
2 changed files with 9 additions and 6 deletions
  1. 4 2
      flaskbb/templates/forum/memberlist.html
  2. 5 4
      flaskbb/templates/macros.html

+ 4 - 2
flaskbb/templates/forum/memberlist.html

@@ -4,6 +4,9 @@
 {% block content %}
 {% from theme('macros.html') import render_pagination, input_group_field %}
 
+{% set order_by = 'desc' if request.args.get('order_by') == 'asc' else 'asc' %}
+{% set sort_by = request.args.get('sort_by') %}
+
 <div class="page-view">
     <ol class="breadcrumb flaskbb-breadcrumb">
         <li><a href="{{ url_for('forum.index') }}">{% trans %}Forum{% endtrans %}</a></li>
@@ -13,7 +16,7 @@
     <div class="row controls-row">
         <div class="col-md-8 col-sm-8 col-xs-8 controls-col">
             <div class="pull-left">
-                {{ render_pagination(users, url_for('forum.memberlist')) }}
+                {{ render_pagination(users, url_for('forum.memberlist'), sort_by=sort_by, asc=(order_by == 'desc')) }}
             </div>
         </div>
         <div class="col-md-4 col-sm-4 col-xs-4 controls-col">
@@ -37,7 +40,6 @@
         </div>
         <div class="panel-body page-body">
             <div class="page-meta">
-                {% set order_by = 'desc' if request.args.get('order_by') == 'asc' else 'asc' %}
                 <div class="col-md-1 col-sm-1 col-xs-1 meta-item">#</div>
                 <div class="col-md-3 col-sm-3 col-xs-5 meta-item">
                     <a href="{{ url_for('forum.memberlist') }}?sort_by=username&order_by={{ order_by }}">{% trans %}Username{% endtrans %}</a>

+ 5 - 4
flaskbb/templates/macros.html

@@ -320,13 +320,15 @@
 </li>
 {% endmacro %}
 
-{% macro render_pagination(page_obj, url, ul_class='') %}
+{% macro render_pagination(page_obj, url, ul_class='', sort_by=None, asc=True) %}
 <ul class='{%- if ul_class -%}{{ ul_class }}{%- else -%}pagination{%- endif -%}'>
+    {% set ordering = 'asc' if asc == True else 'desc' %}
+    {% set sorting = '&sort_by='+(sort_by|urlencode)+'&order_by='+ordering if sort_by is string else '' %}
     <li class="disabled"><a href="#"><span class="pages-label">{% trans %}Pages{% endtrans %}:</span></a></li>
     {%- for page in page_obj.iter_pages() %}
         {% if page %}
             {% if page != page_obj.page %}
-                <li><a href="{{ url }}?page={{ page }}">{{ page }}</a></li>
+                <li><a href="{{ url }}?page={{ page }}{{ sorting }}">{{ page }}</a></li>
             {% else %}
                 <li class="active"><a href="#">{{ page }}</a></li>
             {% endif %}
@@ -335,12 +337,11 @@
         <li class="active"><a href="#">1</a></li>
     {%- endfor %}
     {% if page_obj.has_next %}
-        <li><a href="{{ url }}?page={{ page_obj.next_num }}">&raquo;</a></li>
+        <li><a href="{{ url }}?page={{ page_obj.next_num }}{{ sorting }}">&raquo;</a></li>
     {% endif %}
 </ul>
 {% endmacro %}
 
-
 {% macro render_topic_pagination(page_obj, url) %}
 <ul class="pagination pagelink pull-left">
     <li class="disabled"><a><span class="pages-label">Pages: </span></a></li>