Commits

Chris Perkins  committed a1ec355

much better way of passing params to sprox for the subforms.

  • Participants
  • Parent commits e866b0a

Comments (0)

Files changed (1)

File src/tgext/subform/widgets.py

     __base_widget_type__ = TableSubform
 
 class SelectFieldWithAdd(PropertySingleSelectField):
-    params = {'__field_widget_types__':{}, 
+    subform_params = ('__field_widget_types__',
+                      '__field_validator_types__',
+                      '__field_validators__',
+                      '__base_widget_args__',
+                      '__add_fields__',
+                      '__omit_fields__'
+        )
+
+    params = {'__field_widget_types__':{},
               '__field_validator_types__':{}, 
               '__base_widget_args__':{},
-              '__base_widget_args__':{},
               '__add_fields__':{},
               '__omit_fields__':None,
               'related_subforms':'',
               'add_record_form_type':''
               }
+    __field_widget_types__ = {}
+    __field_validator_types__ = {}
+    __field_validators__ = {}
+    __base_widget_args__ = {}
+    __add_fields__ = {}
+    __omit_fields__ = None
+
     javascript = [select_field_with_add_js,]
     css = [select_field_with_add_css,]
     add_record_form_type = AddRecordSubform
     @property
     def __subform__(self):
 
-        target = self._target
-        target_name = target.__name__.lower()
+        entity = self._target
+        target_name = entity.__name__.lower()
         subform_id = self._subform_id
 
-        fwt = self.__field_widget_types__ or {}
-        fvt = self.__field_validator_types__ or {}
-        bwa = {'id':subform_id}
-        bwa.update(self.__base_widget_args__ or {})
-        of = self.__omit_fields__ or None
-        af = self.__add_fields__ or {}
+        self.__base_widget_args__.update({'id':subform_id})
+
+        if 'submit' not in self.__add_fields__:
+            self.__add_fields__['submit'] = SubmitButton('submit',
+                attrs={'onclick':
+                       "javascript:return function(){%s_helper.validate(); return false;}();"%subform_id})
 
-        af['submit'] = SubmitButton('submit',
-            attrs={'onclick':
-                   "javascript:return function(){%s_helper.validate(); return false;}();"%subform_id})
-        
         class ARF(self.add_record_form_type):
-            __base_widget_args__ = bwa
-            #__base_widget_type__ = TownForm
-            __entity__ = target
-            __field_widget_types__ = fwt
-            __field_validator_types__ = fvt
-            __omit_fields__ = of
-            __add_fields__ = af
+            __entity__ = entity
+
+        #apply the subform params to the ARF
+        for param in self.subform_params:
+            setattr(ARF, param, getattr(self, param))
 
         subform = ARF(self.provider.session)
-        #if subform_id != 'organization_organization_subform':
-        #    assert 0
+
         return subform
     
     @property