changeset 474:b32034020a58

change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
author Akash Sinha <akash2607@gmail.com>
date Sun, 26 Jun 2011 14:26:18 +0530
parents b33a2dca5e8f
children 630c21e18398
files MoinMoin/apps/frontend/views.py MoinMoin/config/default.py MoinMoin/user.py
diffstat 3 files changed, 28 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sat Jun 25 10:44:59 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sun Jun 26 14:26:18 2011 +0530
@@ -542,13 +542,11 @@
     selected_history = []
 
     offset = request.values.get('offset', 0)
-    offset = int(offset)
-    if offset < 0:
-        offset = 0
+    offset = max(int(offset), 0)
 
     results_per_page = int(app.cfg.results_per_page)
     if flaskg.user.valid:
-        results_per_page = flaskg.user.ResultsPerPage(results_per_page)
+        results_per_page = flaskg.user.results_per_page
 
     revcount = 0
     maxcount = offset + results_per_page
@@ -556,7 +554,7 @@
     for rev in history:
         if revcount < offset:
             revcount += 1
-        elif revcount == maxcount:
+        elif results_per_page and revcount == maxcount:
             nextPage = True
             break
         else:
@@ -566,7 +564,7 @@
     if not nextPage:
         revcount = 0
 
-    if offset:
+    if results_per_page and offset:
         previous_offset = max(offset - results_per_page, 0)
     else:
         previous_offset = -1
@@ -584,7 +582,7 @@
     results_per_page = int(app.cfg.results_per_page)
     if flaskg.user.valid:
         bookmark_time = flaskg.user.getBookmark()
-        results_per_page = flaskg.user.ResultsPerPage(results_per_page)
+        results_per_page = flaskg.user.results_per_page # if it is 0, means no paging
     else:
         bookmark_time = None
     item_groups = OrderedDict()
@@ -672,7 +670,7 @@
 
     # Grouping on the date basis
     offset = request.values.get('offset', 0)
-    offset = int(offset)
+    offset = max(int(offset), 0)
     day_count = OrderedDict()
     revcount = 0
     maxrev = results_per_page + offset
@@ -694,32 +692,36 @@
             revcount += len(item_group["revnos"])
         else:
             grouped_history.append(rev_tuples)
-            if revcount < maxrev:
+            if results_per_page and revcount >= maxrev:
+                toappend = False
+                break
+            else:
                 rev_tuples = rev_tuple(rev_date, [item_group])
                 prev_date = rev_date
                 revcount += len(item_group["revnos"])
-            else:
-                toappend = False
-                break
+
     if toappend:
         grouped_history.append(rev_tuples)
         revcount = 0 # this is the last page, no next page present
     del grouped_history[0]  # First tuple will be a null one
 
     # calculate offset for previous page link
-    previous_offset = 0
-    prev_rev_count = day_count.values()
-    prev_rev_count.reverse()
-    for numrev in prev_rev_count:
-        if previous_offset < results_per_page:
-            previous_offset += numrev
+    if results_per_page:
+        previous_offset = 0
+        prev_rev_count = day_count.values()
+        prev_rev_count.reverse()
+        for numrev in prev_rev_count:
+            if previous_offset < results_per_page:
+                previous_offset += numrev
+            else:
+                break
+
+        if offset - previous_offset >= results_per_page:
+            previous_offset = offset - previous_offset
+        elif previous_offset:
+            previous_offset = 0
         else:
-            break
-
-    if offset - previous_offset >= results_per_page:
-        previous_offset = offset - previous_offset
-    elif previous_offset:
-        previous_offset = 0
+            previous_offset = -1
     else:
         previous_offset = -1 # no previous page
 
@@ -1286,7 +1288,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))
+        results_per_page = Integer.using(label=L_('History results per page')).with_properties(placeholder=L_("Number of results per page (0=no paging)")).validated_by(ValueAtLeast(0))
         submit = String.using(default=L_('Save'), optional=True)
 
     dispatch = dict(
--- a/MoinMoin/config/default.py	Sat Jun 25 10:44:59 2011 +0530
+++ b/MoinMoin/config/default.py	Sun Jun 26 14:26:18 2011 +0530
@@ -453,6 +453,7 @@
         ],
         theme_name=None, # None -> use cfg.theme_default
         edit_rows=0,
+        results_per_page=0,
         locale=None, # None -> do browser language detection, otherwise just use this locale
         timezone=None, # None -> use cfg.timezone_default
       ),
--- a/MoinMoin/user.py	Sat Jun 25 10:44:59 2011 +0530
+++ b/MoinMoin/user.py	Sun Jun 26 14:26:18 2011 +0530
@@ -4,7 +4,6 @@
 # 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,18 +788,3 @@
                     sitename=self._cfg.sitename or "Wiki")
         mailok, msg = sendmail.sendmail([self.email], subject, text, mail_from=self._cfg.mail_from)
         return mailok, msg
-
-# -----------------------------------------------------------------
-    # Number of results per page
-    def ResultsPerPage(self, results_per_page=0):
-        """ Get count for number of history results to display per page
-
-        :rtype: int
-        :returns: count value or None
-        """
-        if self.valid:
-            try:
-                results_per_page = self.results_per_page
-            except AttributeError:
-                pass
-        return results_per_page