def all_fields(self): """ Returns all the fields compulsory, predefined, user defined both choosen and not choosen fields This is used for getting all the fields so that the application form creating form can be constructed """ list_of_fields = FormFieldsDataStructure() for field in self.fields: field['name'] = field.get('name', reduce_to_alphanumeric(unicode(field.get('label')).lower())) if field.get('is_compulsory'): list_of_fields.append({'field_details': field, 'meta': {'is_choosen':True, 'is_compulsory':True, 'is_predefined':True, 'is_userdefined': False}}) for field in self.choose_initial_fields_from: if not field.get('is_compulsory'): if field in self.fields: list_of_fields.append({'field_details': field, 'meta': {'is_choosen':True, 'is_compulsory':False, 'is_predefined':True, 'is_userdefined':False}}) else: list_of_fields.append({'field_details': field, 'meta': {'is_choosen':False, 'is_compulsory':False, 'is_predefined':True, 'is_userdefined':False}}) for field in self.fields: if field not in self.choose_initial_fields_from: list_of_fields.append({'field_details': field, 'meta': {'is_choosen':True, 'is_compulsory':False, 'is_predefined':False, 'is_userdefined':True}}) return list_of_fields
def add_field(self, field): """ Adds a new field to the list of fields 'self.fields' after validating Returns True if the field is successfully added or throws ValueError instead (if validation or something fails) """ # lots of stuff left, needs to be done here if not field.get('name'): field['name'] = reduce_to_alphanumeric(unicode(field.get('label')).lower()) if self.validate_field(field): self.fields.append(field) return True