# HG changeset patch # User Sverre Rabbelier # Date 1235232017 0 # Node ID cc58eb1136d6baad09e72baa501ca4f013953753 # Parent 7e54ef90c2104028e0cca62d70121161daf6c878 Hook up dynafields in params.py The helper method getDynaFields converts a list with dynafield dicts to a dictionary with dynaproperties and is used to update the create- and edit_dynaproperties dicts. Patch by: Sverre Rabbelier diff -r 7e54ef90c210 -r cc58eb1136d6 app/soc/views/helper/params.py --- a/app/soc/views/helper/params.py Sat Feb 21 15:59:42 2009 +0000 +++ b/app/soc/views/helper/params.py Sat Feb 21 16:00:17 2009 +0000 @@ -63,6 +63,9 @@ 'tinymce', ] +DEF_FIELD_INIT_PARAMS = ['required', 'widget', 'label', 'initial', 'help_text', + 'error_messages', 'show_hidden_initial'] + def constructParams(params): """Constructs a new params dictionary based on params. @@ -246,6 +249,10 @@ } create_dynaproperties.update(params.get('create_extra_dynaproperties', {})) + # dynafields override any dynaproperties + create_dynafields = getDynaFields(params.get('create_dynafields', {})) + create_dynaproperties = dicts.merge(create_dynafields, create_dynaproperties) + new_params['references'] = [] new_params['create_dynainclude'] = [] + params.get('extra_dynainclude', []) new_params['create_dynaexclude'] = ['scope', 'scope_path'] + \ @@ -258,6 +265,10 @@ } edit_dynaproperties.update(params.get('edit_extra_dynaproperties', {})) + # dynafields override any dynaproperties + edit_dynafields = getDynaFields(params.get('edit_dynafields', {})) + edit_dynaproperties = dicts.merge(edit_dynafields, edit_dynaproperties) + new_params['edit_dynainclude'] = None new_params['edit_dynaexclude'] = None new_params['edit_dynaproperties'] = edit_dynaproperties @@ -284,6 +295,28 @@ return params +def getDynaFields(fields): + """Constructs a new DynaField using params. + + Args: + params: the params dictionary used to extract the dyanfields + param_name: the name of the parameter to use + """ + + dynafields = {} + + # generate the dynafields + for field in fields: + base = field.pop('base') + name = field.pop('name') + passthrough = field.pop('passthrough', DEF_FIELD_INIT_PARAMS) + + dynafield = dynaform.newDynaField(field, base, passthrough) + dynafields[name] = dynafield() + + return dynafields + + def getCreateForm(params, model): """Constructs a new CreateForm using params.