def to_representation(self, instance): representation = super().to_representation(instance) to_represent = { 'facilityId': representation['FacilityId'], 'creditApplicationId': representation['CreditApplicationId'], 'dataView': representation['DataView'], 'details': { 'fields': { 'baseParty': representation['BasePartyId'], 'arrangementType': representation['ArrangementType'], 'facilityParent': representation['FacilityIdParent'], 'facilityId': representation['FacilityId'], 'hostFacilityId': representation['FacilityIdHost'] }, 'grid': generate_params( arrangement_type=representation['ArrangementType'], request_type=representation['RequestType'], data_view=representation['DataView'], instance=representation) }, 'coverage': { 'coverageSummary': get_facility_coverage_summary( representation.get('FacilityId', None)), 'collateralLinkages': CollateralLinkageSerializer(Coverage.objects.filter( FacilityId=representation.get('FacilityId')), model=Coverage, many=True).data } } return to_represent
def post(self, request, *args, **kwargs): if request.data is None: raise Exception('Wrong input data') data = request.data if 'dataView' in data and 'arrangementType' in data and 'requestType' in data: data_view = data['dataView'] arrangement_type = data['arrangementType'] request_type = data['requestType'] params_to_display = generate_params(data_view, arrangement_type, request_type) return JsonResponse(params_to_display, safe=False) raise Exception('Wrong input data')
def to_representation(self, instance): representation = super().to_representation(instance) to_represent = { 'depositId': representation['DepositId'], 'creditApplicationId': representation['CreditApplicationId'], 'dataView': representation['DataView'], 'details': { 'fields': { 'baseParty': representation['BasePartyId'], 'arrangementType': representation['ArrangementType'], 'depositId': representation['DepositId'], 'hostDepositId': representation['DepositIdHost'] }, 'grid': generate_params( arrangement_type=representation['ArrangementType'], request_type=None, data_view=representation['DataView'], instance=representation) } } return to_represent