Allow appending to dynainclude/-exclude
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 28 Jan 2009 00:45:35 +0000
changeset 1021 969566aa110d
parent 1020 846fe3d821fb
child 1022 118896aebfd1
Allow appending to dynainclude/-exclude Patch by: Sverre Rabbelier
app/soc/views/helper/dynaform.py
--- a/app/soc/views/helper/dynaform.py	Wed Jan 28 00:36:30 2009 +0000
+++ b/app/soc/views/helper/dynaform.py	Wed Jan 28 00:45:35 2009 +0000
@@ -99,7 +99,7 @@
 
 
 def extendDynaForm(dynaform, dynainclude=None, dynaexclude=None, 
-                   dynafields=None):
+                   dynafields=None, append=False):
   """Extends an existing dynaform.
 
   If any of dynainclude, dynaexclude or dynafields are not present,
@@ -108,6 +108,10 @@
   While it is rather useles to extend from a dynaform that does not have
   a Meta class, it is allowed, the resulting DynaForm is the same as if
   newDynaForm was called with all extendDynForm's keyword arguments.
+
+  If append is True, the form's original values for include and
+  exclude will be appended to the supplied dynainclude and
+  dynaexclude, which both are still allowed to be None.
   """
 
   # Try to retrieve the Meta class from the existing dynaform
@@ -118,10 +122,13 @@
     dynamodel = getattr(meta, 'model', None)
 
     if not dynainclude:
-      dynainclude = getattr(meta, 'include', None)
+      dynainclude = []
+    if not dynaexclude:
+      dynaexclude = []
 
-    if not dynaexclude:
-      dynaexclude = getattr(meta, 'exclude', None)
+    if append:
+      dynainclude += getattr(meta, 'include', [])
+      dynaexclude += getattr(meta, 'exclude', [])
 
     # The most intersting parameter, the 'extra fields' dictionary
     dynaconf = getattr(meta, 'dynaconf', {})