Пример #1
0
    def surrender_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 surrender 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_surrender_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))
Пример #2
0
    def surrender_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 surrender 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_surrender_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))
Пример #3
0
    def surrender_licence(self, request, pk=None, *args, **kwargs):
        try:
            if pk:
                instance = self.get_object()
                LicenceService.request_surrender_licence(instance, request)
                serializer = DTExternalWildlifeLicenceSerializer(
                    instance, context={'request': request})

                return Response(serializer.data)
            else:
                raise serializers.ValidationError(
                    'Licence ID must be specified')
        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))