in django_airavata/apps/auth/serializers.py [0:0]
def update(self, instance, validated_data):
if instance.value_type == 'text':
text_value = validated_data.pop('text_value')
instance.text.text_value = text_value
instance.text.save()
elif instance.value_type == 'single_choice':
choices = validated_data.pop('choices', [])
choice = choices[0] if len(choices) > 0 else None
other_value = validated_data.pop('other_value', '')
instance.single_choice.choice = choice
instance.single_choice.other_value = other_value
instance.single_choice.save()
elif instance.value_type == 'multi_choice':
choices = validated_data.pop('choices', [])
other_value = validated_data.pop('other_value', '')
# Delete any that are no longer in the set
instance.multi_choice.choices.exclude(value__in=choices).delete()
# Create records as needed for new entries
for choice in choices:
models.ExtendedUserProfileMultiChoiceValueChoice.objects.update_or_create(
value=choice, multi_choice_value=instance.multi_choice)
instance.multi_choice.other_value = other_value
instance.multi_choice.save()
elif instance.value_type == 'user_agreement':
agreement_value = validated_data.pop('agreement_value')
instance.user_agreement.agreement_value = agreement_value
instance.user_agreement.save()
instance.save()
return instance