def manage_fields(the_form, portal_type, mode): """ Remove, reorder and restrict fields """ fields_schemas = getattr(getProjectSpace(the_form.context), '{}_fields'.format(portal_type), []) if not fields_schemas: return to_input = [] to_display = [] for fields_schema in reversed(fields_schemas): field_name = fields_schema['field_name'] read_condition = fields_schema.get('read_tal_condition') or "" write_condition = fields_schema.get('write_tal_condition') or "" if _evaluateExpression(the_form.context, expression=read_condition): to_display.append(field_name) if _evaluateExpression(the_form.context, expression=write_condition): to_input.append(field_name) field = remove(the_form, field_name) if field is not None and field_name in to_display: add(the_form, field, index=0) if mode != 'view' and field_name not in to_input: field.mode = "display" for group in [the_form] + the_form.groups: for field_name in group.fields: if field_name == 'reference_number' and mode != 'view': continue if field_name not in to_display: group.fields = group.fields.omit(field_name)
def add(self, *args, **kwargs): """Add one or more fields. Keyword argument 'index' can be used to specify an index to insert at. Keyword argument 'group' can be used to specify the label of a group, which will be found and used or created if it doesn't exist. """ utils.add(self.form, *args, **kwargs)
def updateFields(self): super(RegistrationForm, self).updateFields() if self.showForm: z3cform_utils.add(self, IHiddenVerifiedEmail, prefix="") else: self.fields = field.Fields(IHiddenVerifiedEmail, prefix="") self.fields['confirmed_email'].mode = interfaces.HIDDEN_MODE self.fields['confirmed_code'].mode = interfaces.HIDDEN_MODE
def updateFields(self): self.form.groups = [] if not hasattr(self, "additionalSchemata"): return for prefix, group, schema in self.additionalSchemata: fields = field.Fields(schema, prefix=prefix) if hasattr(self, "customize_fields"): self.customize_fields(fields) z3cutils.add(self.form, fields, group=group)
def updateFields(self): self.form.groups = [] if not hasattr(self, 'additionalSchemata'): return for prefix, group, schema in self.additionalSchemata: fields = field.Fields(schema, prefix=prefix) if hasattr(self, 'customize_fields'): self.customize_fields(fields) z3cutils.add(self.form, fields, group=group)
def addDynamicFields(form, reg_fields): # build fieldsets found_sets = {} for fielddata in reg_fields: if fielddata != None and fielddata['fieldset'] != "" and fielddata != "<NO_VALUE>": if fielddata['fieldset'] in found_sets: found_sets[fielddata['fieldset']].append(fielddata['name']) else: found_sets[fielddata['fieldset']] = [fielddata['name']] counter = 0 #import pdb; pdb.set_trace() for fieldset in found_sets: #field = Fieldset("dynamicfieldset%d" % (counter,), # label=_(fieldset), # fields=found_sets[fieldset]) #utils.add(form, field) #form.fieldset("dynamicfieldset" + counter, # label=_(fieldset), # fields=found_sets[fieldset]) counter += 1 # build fields for fielddata in reg_fields: kwargs = dict(title=unicode(fielddata['name']), required=fielddata['required']) if fielddata['fieldtype'] == 'List': vocab = [] for value in fielddata.get('configuration').splitlines(): vocab.append(SimpleTerm(value=value, title=value)) kwargs['value_type'] = schema.Choice( vocabulary=SimpleVocabulary(vocab)) field = getattr(schema, fielddata['fieldtype'])(**kwargs) field.__name__ = str(fielddata['name']) field.interface = IRegistration utils.add(form, field)