changeset 5841:8b3c4b85921b

action/rss_rc.py: param parsing rewritten to support retrieval of default values from wiki configuration.
author Eugene Syromyatnikov <evgsyr@gmail.com>
date Wed, 16 May 2012 15:42:09 +0400
parents 4a982b04461d
children 97e36f417f6e
files MoinMoin/action/rss_rc.py MoinMoin/config/multiconfig.py
diffstat 2 files changed, 47 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/rss_rc.py	Wed May 16 04:29:16 2012 +0400
+++ b/MoinMoin/action/rss_rc.py	Wed May 16 15:42:09 2012 +0400
@@ -30,31 +30,37 @@
     cfg = request.cfg
 
     # get params
-    items_limit = 100
-    lines_limit = 100
+    def_max_items = max_items = getattr(cfg, "rss_items_default", 15)
+    items_limit = getattr(cfg, "rss_items_limit", 100)
+    unique = getattr(cfg, "rss_unique", 0)
+    diffs = getattr(cfg, "rss_diffs", 0)
+    ddiffs = getattr(cfg, "rss_ddiffs", 0)
+    max_lines = getattr(cfg, "rss_lines_default", 20)
+    lines_limit = getattr(cfg, "rss_lines_limit", 100)
+
     try:
-        max_items = int(request.values['items'])
-        max_items = min(max_items, items_limit) # not more than `items_limit`
-    except (KeyError, ValueError):
-        # not more than 15 items in a RSS file by default
-        max_items = 15
+        max_items = min(int(request.values.get('items', max_items)),
+                        items_limit)
+    except ValueError:
+        pass
     try:
-        unique = int(request.values.get('unique', 0))
+        unique = int(request.values.get('unique', unique))
     except ValueError:
-        unique = 0
+        pass
     try:
-        diffs = int(request.values.get('diffs', 0))
+        diffs = int(request.values.get('diffs', diffs))
     except ValueError:
-        diffs = 0
+        pass
     ## ddiffs inserted by Ralf Zosel <ralf@zosel.com>, 04.12.2003
     try:
-        ddiffs = int(request.values.get('ddiffs', 0))
+        ddiffs = int(request.values.get('ddiffs', ddiffs))
     except ValueError:
-        ddiffs = 0
+        pass
     try:
-        max_lines = min(int(request.values.get('lines', 20)), lines_limit)
+        max_lines = min(int(request.values.get('lines', max_lines)),
+                        lines_limit)
     except ValueError:
-        max_lines = 20
+        pass
 
     # get data
     log = editlog.EditLog(request)
@@ -122,7 +128,7 @@
         handler.startDocument()
         handler._out.write(
             '<!--\n'
-            '    Add an "items=nnn" URL parameter to get more than the default 15 items.\n'
+            '    Add an "items=nnn" URL parameter to get more than the default %d items.\n'
             '    You cannot get more than %d items though.\n'
             '    \n'
             '    Add "unique=1" to get a list of changes where page names are unique,\n'
@@ -137,8 +143,8 @@
             '    \n'
             '    Current settings: items=%i, unique=%i, diffs=%i, ddiffs=%i, \n'
             '    lines=%i\n'
-            '-->\n' % (items_limit, lines_limit, max_items, unique, diffs,
-                       ddiffs, max_lines)
+            '-->\n' % (def_max_items, items_limit, lines_limit, max_items,
+                       unique, diffs, ddiffs, max_lines)
             )
 
         # emit channel description
--- a/MoinMoin/config/multiconfig.py	Wed May 16 04:29:16 2012 +0400
+++ b/MoinMoin/config/multiconfig.py	Wed May 16 15:42:09 2012 +0400
@@ -1285,6 +1285,29 @@
       ('include', [], 'List of pathes to backup.'),
       ('exclude', lambda self, filename: False, 'Function f(self, filename) that tells whether a file should be excluded from backup. By default, nothing is excluded.'),
     )),
+    'rss': ('RSS settings',
+        'These settings control RSS behaviour.',
+    (
+      ('items_default', 15, "Default maximum items value for RSS feed. Can be "
+                            "changed via items URL query parameter of rss_rc "
+                            "action."),
+      ('items_limit', 100, "Limit for item count got via RSS (i. e. user "
+                           "can't get more than items_limit items even via "
+                           "changing items URL query parameter)."),
+      ('unique', 0, "If set to 1, for each page name only one RSS item would "
+                    "be shown. Can be changed via unique rss_rc action URL "
+                    "query parameter."),
+      ('diffs', 0, "Add diffs in RSS item descriptions by default. Can be "
+                   "changed via diffs URL query parameter of rss_rc action."),
+      ('ddiffs', 0, "If set to 1, links to diff view instead of page itself "
+                    "would be generated by default. Can be changed via ddiffs "
+                    "URL query parameter of rss_rc action."),
+      ('lines_default', 20, "Default line count limit for diffs added as item "
+                            "descriptions for RSS items. Can be changed via "
+                            "lines URL query parameter of rss_rc action."),
+      ('lines_limit', 100, "Limit for possible line count for diffs added as "
+                           "item descriptions in RSS."),
+    )),
 }
 
 def _add_options_to_defconfig(opts, addgroup=True):