Ejemplo n.º 1
0
    def compliances_external(self, request, *args, **kwargs):
        """
        Paginated serializer for datatables - used by the external dashboard

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

        qs = self.get_queryset().exclude(processing_status='future')
        #qs = ProposalFilterBackend().filter_queryset(self.request, qs, self)
        qs = self.filter_queryset(qs)
        #qs = qs.order_by('lodgement_number', '-issue_date').distinct('lodgement_number')

        # 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(proposal__org_applicant_id=applicant_id)
        submitter_id = request.GET.get('submitter_id', None)
        if submitter_id:
            qs = qs.filter(proposal__submitter_id=submitter_id)
        self.paginator.page_size = qs.count()
        result_page = self.paginator.paginate_queryset(qs, request)
        serializer = ComplianceSerializer(result_page,
                                          context={'request': request},
                                          many=True)
        return self.paginator.get_paginated_response(serializer.data)
Ejemplo n.º 2
0
 def delete_document(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         doc = request.data.get('document')
         instance.delete_document(request, doc)
         serializer = ComplianceSerializer(instance)
         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[0].encode('utf-8')))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))