Exemplo n.º 1
0
    def suspend_purposes(self, request, pk=None, *args, **kwargs):
        '''
        Request to suspend purposes.
        '''
        MSG_NOAUTH = 'You are not authorised to suspend licenced activities'
        # MSG_NOSAME = 'Purposes must all be of the same licence activity'
        try:
            purpose_ids_list = request.data.get('purpose_ids_list', None)

            if not request.user.has_perm('wildlifecompliance.issuing_officer'):
                raise serializers.ValidationError(MSG_NOAUTH)

            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_suspend_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))
Exemplo n.º 2
0
    def suspend_licence(self, request, pk=None, *args, **kwargs):
        try:
            if not request.user.has_perm('wildlifecompliance.issuing_officer'):
                raise serializers.ValidationError(
                    'You are not authorised to suspend licences')
            if pk:
                instance = self.get_object()
                LicenceService.request_suspend_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))