in django_airavata/apps/auth/serializers.py [0:0]
def create(self, validated_data):
field_type = validated_data.pop('field_type')
other = validated_data.pop('other', False)
choices = validated_data.pop('choices', [])
checkbox_label = validated_data.pop('checkbox_label', '')
links = validated_data.pop('links', [])
if field_type == 'text':
instance = models.ExtendedUserProfileTextField.objects.create(**validated_data)
elif field_type == 'single_choice':
instance = models.ExtendedUserProfileSingleChoiceField.objects.create(**validated_data, other=other)
# add choices
for choice in choices:
choice.pop('id', None)
instance.choices.create(**choice)
elif field_type == 'multi_choice':
instance = models.ExtendedUserProfileMultiChoiceField.objects.create(**validated_data, other=other)
# add choices
for choice in choices:
choice.pop('id', None)
instance.choices.create(**choice)
elif field_type == 'user_agreement':
instance = models.ExtendedUserProfileAgreementField.objects.create(**validated_data, checkbox_label=checkbox_label)
else:
raise Exception(f"Unrecognized field type: {field_type}")
# create links
for link in links:
link.pop('id', None)
instance.links.create(**link)
return instance