Ejemplo n.º 1
0
    def approvals_external(self, request, *args, **kwargs):
        """
        Paginated serializer for datatables - used by the internal and external dashboard (filtered by the get_queryset method)

        To test:
            http://localhost:8000/api/approval_paginated/approvals_external/?format=datatables&draw=1&length=2
        """

        #import ipdb; ipdb.set_trace()
        #qs = self.queryset().order_by('lodgement_number', '-issue_date').distinct('lodgement_number')
        #qs = ProposalFilterBackend().filter_queryset(self.request, qs, self)

        ids = self.get_queryset().order_by(
            'lodgement_number',
            '-issue_date').distinct('lodgement_number').values_list('id',
                                                                    flat=True)
        qs = Approval.objects.filter(id__in=ids)
        qs = self.filter_queryset(qs)

        # on the internal organisations dashboard, filter the Proposal/Approval/Compliance datatables by applicant/organisation
        applicant_id = request.GET.get('org_id')
        if applicant_id:
            qs = qs.filter(org_applicant_id=applicant_id)
        submitter_id = request.GET.get('submitter_id', None)
        if submitter_id:
            qs = qs.filter(submitter_id=submitter_id)

        self.paginator.page_size = qs.count()
        result_page = self.paginator.paginate_queryset(qs, request)
        serializer = ApprovalSerializer(result_page,
                                        context={'request': request},
                                        many=True)
        return self.paginator.get_paginated_response(serializer.data)
Ejemplo n.º 2
0
 def approval_surrender(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         serializer = ApprovalSurrenderSerializer(data=request.data)
         serializer.is_valid(raise_exception=True)
         instance.approval_surrender(request, serializer.validated_data)
         serializer = ApprovalSerializer(instance,
                                         context={'request': request})
         return Response(serializer.data)
     except serializers.ValidationError:
         print(traceback.print_exc())
         raise
     except ValidationError as e:
         if hasattr(e, 'error_dict'):
             raise serializers.ValidationError(repr(e.error_dict))
         else:
             raise serializers.ValidationError(repr(e[0].encode('utf-8')))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))