def make_mandatory_fields(self, project_uuid, profile_uuid, item_type): """ makes mandatory predicates for a profile depending on it's type """ if item_type in InputField.PREDICATES_OC: mandatory_predicates = InputField.PREDICATES_OC[item_type] exist_man_fields = InputField.objects\ .filter(profile_uuid=profile_uuid, predicate_uuid__in=mandatory_predicates)[:1] if len(exist_man_fields) > 0: # at least one of the mandatory fields already exists, # we sould add missing mandatory fields to this field-group fgroup_uuid = exist_man_fields[0].fgroup_uuid else: # we don't have any mandatory fields for this profile, # so create a group for the mandatory fields fgroup_uuid = GenUUID.uuid4() fgroup_uuid = str(fgroup_uuid) fgroup = InputFieldGroup() fgroup.uuid = fgroup_uuid fgroup.project_uuid = project_uuid fgroup.profile_uuid = profile_uuid fgroup.label = 'Open Context Required Fields' fgroup.visibility = 'open' fgroup.sort = 0 fgroup.note = 'Automatically generated group of mandatory fields for ' + item_type + ' records.' fgroup.save() new_field = 1 for man_pred in mandatory_predicates: # now check to see if the current mandatory predicate is already present exist_man_field = InputField.objects\ .filter(profile_uuid=profile_uuid, predicate_uuid=man_pred) if len(exist_man_field) < 1: # only create the mandatory fields if they don't already exist for this profile f_uuid = GenUUID.uuid4() f_uuid = str(f_uuid) inp_field = InputField() inp_field.uuid = f_uuid inp_field.project_uuid = project_uuid inp_field.profile_uuid = profile_uuid inp_field.fgroup_uuid = fgroup_uuid inp_field.row_num = 1 inp_field.col_num = 1 inp_field.sort = new_field inp_field.predicate_uuid = man_pred preset = InputField.PREDICATE_ITEMS[inp_field.predicate_uuid] inp_field.label = preset['label'] inp_field.note = preset['note'] inp_field.validation = json.dumps(preset['validation'], indent=4, ensure_ascii=False) inp_field.save() new_field += 1