예제 #1
0
    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))
예제 #2
0
    def reinstate_purposes(self, request, pk=None, *args, **kwargs):
        MSG_NOAUTH = 'You are not authorised to reinstate 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_reinstate_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 reactivate_renew_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 reactivate renew for 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 purpose_ids_list and pk:
             licence_activity_id = LicencePurpose.objects.filter(id__in=purpose_ids_list).\
                                     first().licence_activity_id
             instance = self.get_object()
             can_reactivate_renew_purposes = instance.get_latest_purposes_for_licence_activity_and_action(
                 licence_activity_id,
                 WildlifeLicence.ACTIVITY_PURPOSE_ACTION_REACTIVATE_RENEW)
             can_reactivate_renew_purposes_ids_list = [
                 purpose.id
                 for purpose in can_reactivate_renew_purposes.order_by('id')
             ]
             if not set(purpose_ids_list).issubset(
                     can_reactivate_renew_purposes_ids_list):
                 raise serializers.ValidationError(
                     'Renew for selected purposes cannot be reactivated')
             instance.apply_action_to_purposes(
                 request,
                 WildlifeLicence.ACTIVITY_PURPOSE_ACTION_REACTIVATE_RENEW)
             serializer = DTExternalWildlifeLicenceSerializer(
                 instance, context={'request': request})
             return Response(serializer.data)
         else:
             raise serializers.ValidationError(
                 'Licence ID and Purpose IDs list 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))
예제 #4
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))
예제 #5
0
 def external_datatable_list(self, request, *args, **kwargs):
     self.serializer_class = DTExternalWildlifeLicenceSerializer
     # Filter for WildlifeLicence objects that have a current application linked with an
     # ApplicationSelectedActivity that has been ACCEPTED
     user_orgs = [
         org.id
         for org in request.user.wildlifecompliance_organisations.all()
     ]
     asa_accepted = ApplicationSelectedActivity.objects.filter(
         Q(application__org_applicant_id__in=user_orgs)
         | Q(application__proxy_applicant=request.user)
         | Q(application__submitter=request.user)).filter(
             processing_status=ApplicationSelectedActivity.
             PROCESSING_STATUS_ACCEPTED)
     queryset = WildlifeLicence.objects.filter(
         current_application__in=asa_accepted.values_list('application_id',
                                                          flat=True))
     # Filter by org
     org_id = request.GET.get('org_id', None)
     if org_id:
         queryset = queryset.filter(
             current_application__org_applicant_id=org_id)
     # Filter by proxy_applicant
     proxy_applicant_id = request.GET.get('proxy_applicant_id', None)
     if proxy_applicant_id:
         queryset = queryset.filter(
             current_application__proxy_applicant_id=proxy_applicant_id)
     # Filter by submitter
     submitter_id = request.GET.get('submitter_id', None)
     if submitter_id:
         queryset = queryset.filter(
             current_application__submitter_id=submitter_id)
     queryset = self.filter_queryset(queryset)
     self.paginator.page_size = queryset.count()
     result_page = self.paginator.paginate_queryset(queryset, request)
     serializer = DTExternalWildlifeLicenceSerializer(
         result_page, context={'request': request}, many=True)
     return self.paginator.get_paginated_response(serializer.data)
예제 #6
0
 def regenerate_licence_pdf(self, request, pk=None, *args, **kwargs):
     try:
         if not request.user.has_perm('wildlifecompliance.issuing_officer'):
             raise serializers.ValidationError(
                 'You are not authorised to reinstate licences')
         if pk:
             instance = self.get_object()
             instance.generate_doc()
             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))