From 6d2ea38e4e7814768d21c43e43a1f37e65f37c63 Mon Sep 17 00:00:00 2001 From: sks444 <krishnasingh.ss30@gmail.com> Date: Wed, 30 Sep 2020 14:10:06 +0530 Subject: [PATCH] Make determination outcome field as read_only for update --- hypha/apply/api/v1/determination/views.py | 11 +++++++++-- hypha/apply/api/v1/stream_serializers.py | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/hypha/apply/api/v1/determination/views.py b/hypha/apply/api/v1/determination/views.py index 216998910..ee4ffffcc 100644 --- a/hypha/apply/api/v1/determination/views.py +++ b/hypha/apply/api/v1/determination/views.py @@ -1,3 +1,4 @@ +from django import forms from django.conf import settings from django.db import transaction from django.shortcuts import get_object_or_404 @@ -120,8 +121,14 @@ class SubmissionDeterminationViewSet( outcome_choices = outcome_choices_for_phase( submission, self.request.user ) - # Outcome field choices need to be set according to the phase. - form_fields[field_block.id].choices = outcome_choices + if self.action == 'update': + # Outcome can not be edited after being set once, so we do not + # need to render this field. + # form_fields.pop(field_block.id) + form_fields[field_block.id].widget = forms.TextInput(attrs={'readonly': 'readonly'}) + else: + # Outcome field choices need to be set according to the phase. + form_fields[field_block.id].choices = outcome_choices return form_fields @action(detail=False, methods=['get']) diff --git a/hypha/apply/api/v1/stream_serializers.py b/hypha/apply/api/v1/stream_serializers.py index 69e99b953..a33383b19 100644 --- a/hypha/apply/api/v1/stream_serializers.py +++ b/hypha/apply/api/v1/stream_serializers.py @@ -110,6 +110,10 @@ class WagtailSerializer: if attrs.get('required') and 'default' in attrs: del attrs['required'] + # avoid "May not set both `read_only` and `required`" + if form_field.widget.attrs.get('readonly', False) == 'readonly': + attrs['read_only'] = True + del attrs['required'] return attrs def get_serializer_field_class(self, field): -- GitLab