def cancel_purposes(self, request, pk=None, *args, **kwargs): try: purpose_ids_list = request.data.get('purpose_ids_list', None) # if not type(purpose_ids_list) == list: # raise serializers.ValidationError( # 'Purpose IDs must be a list') if not request.user.has_perm('wildlifecompliance.issuing_officer'): raise serializers.ValidationError( 'You are not authorised to cancel licenced activities') # if LicencePurpose.objects.filter(id__in=purpose_ids_list).\ # values_list('licence_activity_id',flat=True).\ # distinct().count() != 1: # raise serializers.ValidationError( # 'Selected purposes must all be of the same licence activity') if not purpose_ids_list and pk: raise serializers.ValidationError( 'Licence ID and Purpose IDs list must be specified') instance = self.get_object() LicenceService.request_cancel_licence(instance, request) serializer = DTExternalWildlifeLicenceSerializer( instance, context={'request': request}) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: print(traceback.print_exc()) raise serializers.ValidationError(repr(e.error_dict)) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))
def cancel_purposes(self, request, pk=None, *args, **kwargs): try: purpose_ids_list = request.data.get('purpose_ids_list', None) if not request.user.has_perm('wildlifecompliance.issuing_officer'): raise serializers.ValidationError( 'You are not authorised to cancel licenced activities') if not purpose_ids_list and pk: raise serializers.ValidationError( 'Licence ID and Purpose IDs list must be specified') instance = self.get_object() LicenceService.request_cancel_licence(instance, request) serializer = DTExternalWildlifeLicenceSerializer( instance, context={'request': request}) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: print(traceback.print_exc()) raise serializers.ValidationError(repr(e.error_dict)) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))