changeset 584:7a22cd126aa4

merged repos
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 16 Mar 2012 09:10:20 +0100
parents 5726458585d7 (current diff) 374033c4eb26 (diff)
children d6a7c36f06f5
files
diffstat 1 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Fri Mar 16 08:55:05 2012 +0100
+++ b/data/plugin/parser/text_x_arnica.py	Fri Mar 16 09:10:20 2012 +0100
@@ -16,6 +16,7 @@
 """
 
 import os, re
+from inspect import getargspec
 from random import randint
 from MoinMoin import search
 from MoinMoin import wikiutil
@@ -24,19 +25,21 @@
 from MoinMoin.Page import Page
 
 parser_name = __name__.split('.')[-1]
+# is the name of the plugin and also used as prefix for wikiconfig plugin defaults.
+plugin_name = "arnica"
 
 
-def arnica_settings(target_page=u'', columns=4, file_regex=u'.',
-                    image_for_webnail=False,
-                    show_text=True, show_date=True, show_tools=False, show_album_title=True,
-                    sort_by=("name", "date", "alias"),
-                    reverse_sort=False,
-                    only_items=False, template_itemlist=False,
-                    album=False, album_title=unicode, album_image=u'', album_link_page=False,
-                    album_overview=False, album_short_title=False,
-                    renew=False,
-                    thumbnail_width=128,
-                    webnail_width=640):
+def settings(target_page=u'', columns=4, file_regex=u'.',
+             image_for_webnail=False,
+             show_text=True, show_date=True, show_tools=False, show_album_title=True,
+             sort_by=("name", "date", "alias"),
+             reverse_sort=False,
+             only_items=False, template_itemlist=False,
+             album=False, album_title=unicode, album_image=u'', album_link_page=False,
+             album_overview=False, album_short_title=False,
+             renew=False,
+             thumbnail_width=128,
+             webnail_width=640):
     """ dummy function to initialize all default parameters for arnica. The parameters are checked for wrong input.
     @param target_page: page to read attachments from. empty pagename is current page.
                         for album_overview, target_page is now a string for title search. alternatively it is possible to use regex:... or category:... (e.g. regex:title:.* for all pages)
@@ -65,6 +68,20 @@
     """
     return locals()
 
+def update_defaults_by_wikiconfig(cfg, plugin_name, settings_function):
+    """ function to overwrite defaults of settings_function by wikiconfig attributes
+    @param cfg: wiki config instance
+    @param plugin_name: this is the namespace prefix for parameters of the plugin (plugin_name_param has to be defined in wikiconfig).
+    @param settings_function: function whose defaults have to be updated by wikiconfig 
+    """
+    def get_arg_default(cfg, plugin_name, name, settings_function):
+        try:
+            return getattr(cfg, "%s_%s"%(plugin_name, name))
+        except AttributeError:
+            return getargspec(settings_function)[3][getargspec(settings_function)[0].index(name)]
+    settings_function.func_defaults = tuple([get_arg_default(cfg, plugin_name, arg, settings_function) 
+                                             for arg in getargspec(settings_function)[0]])
+
 def _get_files(request, pagename):
     """ get files dependent on isPicture and ignores tmp. files
     @param pagename: name of the page where to get attachments
@@ -90,11 +107,12 @@
         args = kw.get('format_args', '')
         self.init_settings = False
         self.top_image_sorted = None
+        update_defaults_by_wikiconfig(request.cfg, plugin_name, settings)
         # we use a macro definition to initialize the default init parameters
         # if a user enters a wrong parameter the failure is shown by the exception
         try:
-            settings = wikiutil.invoke_extension_function(request, arnica_settings, args)
-            for key, value in settings.items():
+            arnica_settings = wikiutil.invoke_extension_function(request, settings, args)
+            for key, value in arnica_settings.items():
                 setattr(self, key, value)
             # saves the state of valid input
             self.init_settings = True