changeset 472:c04d1ca903c7

paging for item history results added
author Akash Sinha <akash2607@gmail.com>
date Fri, 24 Jun 2011 16:36:24 +0530
parents 17ee0418e93c
children b33a2dca5e8f
files MoinMoin/apps/frontend/views.py MoinMoin/templates/history.html
diffstat 2 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Fri Jun 24 16:06:17 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Fri Jun 24 16:36:24 2011 +0530
@@ -539,12 +539,45 @@
 @frontend.route('/+history/<itemname:item_name>')
 def history(item_name):
     history = flaskg.storage.history(item_name=item_name)
+    selected_history = []
+
+    offset = request.values.get('offset', 0)
+    offset = int(offset)
+    if offset < 0:
+        offset = 0
+
+    results_per_page = int(app.cfg.results_per_page)
+    if flaskg.user.valid:
+        results_per_page = flaskg.user.ResultsPerPage(results_per_page)
+
+    revcount = 0
+    maxcount = offset + results_per_page
+    nextPage = False
+    for rev in history:
+        if revcount < offset:
+            revcount += 1
+        elif revcount == maxcount:
+            nextPage = True
+            break
+        else:
+            selected_history.append(rev)
+            revcount += 1
+
+    if not nextPage:
+        revcount = 0
+
+    if offset:
+        previous_offset = max(offset - results_per_page, 0)
+    else:
+        previous_offset = -1
+
     return render_template('history.html',
                            item_name=item_name, # XXX no item here
-                           history=history,
+                           history=selected_history,
+                           offset=revcount,
+                           previous_offset=previous_offset,
                           )
 
-
 @frontend.route('/+history')
 def global_history():
     history = flaskg.storage.history(item_name='')
--- a/MoinMoin/templates/history.html	Fri Jun 24 16:06:17 2011 +0530
+++ b/MoinMoin/templates/history.html	Fri Jun 24 16:36:24 2011 +0530
@@ -2,7 +2,16 @@
 {% import "utils.html" as utils %}
 {% block content %}
     {% if history %}
+    <div class='moin-offset-links'>
+        {% if previous_offset >= 0 %}
+            <a href="{{ url_for('frontend.history', item_name=item_name, offset=previous_offset) }}" title="{{ _("Previous") }}">&laquo;</a>
+        {% endif %}
+        {% if offset %}
+            <a href="{{ url_for('frontend.history', item_name=item_name, offset=offset) }}" title="{{ _("Next") }}">&raquo;</a>
+        {% endif %}
+    </div>
     <h1>{{ _("History of '%(item_name)s'", item_name=item_name) }}</h1>
+    <div class="moin-clr"></div>
     <form action="{{ url_for('frontend.diff', item_name=item_name) }}" method="GET">
         <div id="moin-page-history">
         <table>