changeset 469:82261b274b68

Option to configure result count per page for pagination of history results, added in usersettings.
author Akash Sinha <akash2607@gmail.com>
date Thu, 23 Jun 2011 00:13:58 +0530
parents 511a2a2e9950
children bba40d458d9e
files MoinMoin/apps/frontend/views.py MoinMoin/config/default.py MoinMoin/templates/usersettings.html MoinMoin/user.py
diffstat 4 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon Jun 20 11:18:18 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Thu Jun 23 00:13:58 2011 +0530
@@ -27,7 +27,7 @@
 from flaskext.themes import get_themes_list
 
 from flatland import Form, String, Integer, Boolean, Enum
-from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted
+from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted, ValueAtLeast
 
 from jinja2 import Markup
 
@@ -548,8 +548,10 @@
 @frontend.route('/+history')
 def global_history():
     history = flaskg.storage.history(item_name='')
+    count = 0
     if flaskg.user.valid:
         bookmark_time = flaskg.user.getBookmark()
+        count = flaskg.user.getCount()
     else:
         bookmark_time = None
     item_groups = OrderedDict()
@@ -638,8 +640,9 @@
     # Grouping on the date basis
     offset = request.values.get('offset', 0)
     offset = int(offset)
+    if not count:
+        count = int(app.cfg.results_per_page)
 
-    count = 50 # something default
     day_count = OrderedDict()
     revcount = 0
     maxrev = count + offset
@@ -1253,6 +1256,7 @@
         theme_name = Enum.using(label=L_('Theme name')).with_properties(labels=dict(themes_available)).valued(*themes_keys)
         css_url = String.using(label=L_('User CSS URL'), optional=True).with_properties(placeholder=L_("Give the URL of your custom CSS (optional)")).validated_by(URLValidator())
         edit_rows = Integer.using(label=L_('Editor size')).with_properties(placeholder=L_("Editor textarea height (0=auto)")).validated_by(Converted())
+        results_per_page = Integer.using(label=L_('History results per page'), optional=True).with_properties(placeholder=L_("Number of results per page")).validated_by(ValueAtLeast(1))
         submit = String.using(default=L_('Save'), optional=True)
 
     dispatch = dict(
@@ -1338,7 +1342,6 @@
         flash(_("You must log in to use bookmarks."), "error")
     return redirect(url_for('frontend.global_history'))
 
-
 @frontend.route('/+diffraw/<path:item_name>')
 def diffraw(item_name):
     # TODO get_item and get_revision calls may raise an AccessDeniedError.
--- a/MoinMoin/config/default.py	Mon Jun 20 11:18:18 2011 +0530
+++ b/MoinMoin/config/default.py	Thu Jun 23 00:13:58 2011 +0530
@@ -3,6 +3,7 @@
 # Copyright: 2005-2011 MoinMoin:ThomasWaldmann
 # Copyright: 2008      MoinMoin:JohannesBerg
 # Copyright: 2010      MoinMoin:DiogenesAugusto
+# Copyright: 2011      MoinMoin:AkashSinha
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
@@ -394,6 +395,10 @@
     ('edit_ticketing', True, None),
   )),
   # ==========================================================================
+  'paging': ('Paging related', None, (
+    ('results_per_page', 50, "Number of results to be shown on a single page in pagination"),
+  )),
+  # ==========================================================================
   'data': ('Data storage', None, (
     ('data_dir', './data/', "Path to the data directory."),
     ('plugin_dirs', [], "Plugin directories."),
--- a/MoinMoin/templates/usersettings.html	Mon Jun 20 11:18:18 2011 +0530
+++ b/MoinMoin/templates/usersettings.html	Thu Jun 23 00:13:58 2011 +0530
@@ -64,6 +64,7 @@
     {{ forms.render_select(gen, form['theme_name']) }}
     {{ forms.render_field(gen, form['css_url'], 'url') }}
     {{ forms.render_field(gen, form['edit_rows'], 'text') }}
+    {{ forms.render_field(gen, form['results_per_page'], 'number') }}
   </dl>
   {{ gen.input(form['submit'], type='submit') }}
 {{ gen.form.close() }}
--- a/MoinMoin/user.py	Mon Jun 20 11:18:18 2011 +0530
+++ b/MoinMoin/user.py	Thu Jun 23 00:13:58 2011 +0530
@@ -4,6 +4,7 @@
 # Copyright: 2007 MoinMoin:HeinrichWendel
 # Copyright: 2008 MoinMoin:ChristopherDenter
 # Copyright: 2010 MoinMoin:DiogenesAugusto
+# Copyright: 2011 MoinMoin:AkashSinha
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
@@ -789,3 +790,18 @@
         mailok, msg = sendmail.sendmail([self.email], subject, text, mail_from=self._cfg.mail_from)
         return mailok, msg
 
+# -----------------------------------------------------------------
+    # Result Count
+    def getCount(self):
+        """ Get count for number of history results to display per page
+
+        :rtype: int
+        :returns: count value or None
+        """
+        count = None
+        if self.valid:
+            try:
+                count = self.results_per_page
+            except AttributeError:
+                pass
+        return count