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(applicant_id=applicant_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)
def approval_cancellation(self, request, *args, **kwargs): instance = self.get_object() serializer = ApprovalCancellationSerializer(data=request.data) serializer.is_valid(raise_exception=True) instance.approval_cancellation(request, serializer.validated_data) serializer = ApprovalSerializer(instance, context={'request': request}) return Response(serializer.data)
def approval_pdf_view_log(self, request, *args, **kwargs): try: instance = self.get_object() instance.pdf_view_log(request) serializer = ApprovalSerializer(instance,context={'request':request}) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: handle_validation_error(e) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))
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: handle_validation_error(e) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))
def approval_pdf_view_log(self, request, *args, **kwargs): try: instance = self.get_object() instance.pdf_view_log(request) 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))
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))