fork download
  1. @swagger_auto_schema(responses=response_dict(OutputSerializer()))
  2. def get(self, request, report_id):
  3. # 1) Ensure report exists
  4. report = get_object_or_404(CliReport, id=report_id)
  5.  
  6. # 2) Prefetch user approval ranges onto request.user as `approval_ranges`
  7. prefetch_related_objects(
  8. [request.user],
  9. Prefetch(
  10. "cli_approval_ranges",
  11. queryset=CliApprovalMatrix.objects.order_by("count_range_min", "count_range_max"),
  12. to_attr="approval_ranges",
  13. ),
  14. )
  15.  
  16. ranges = getattr(request.user, "approval_ranges", []) or []
  17. customer_count = report.customers_count
  18.  
  19. authorized = False
  20. if customer_count is not None and ranges:
  21. for ar in ranges:
  22. if ar.count_range_min <= customer_count and customer_count <= ar.count_range_max:
  23. authorized = True
  24. break
  25.  
  26. can_approve = bool(authorized)
  27. can_publish = bool(authorized)
  28.  
  29.  
  30. data = self.OutputSerializer(
  31. {"can_publish": can_publish, "can_approve": can_approve}
  32. ).data
  33. return Response(data, status=status.HTTP_200_OK)
  34.  
Success #stdin #stdout #stderr 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "@swagger_auto_schema(responses=response_dict(OutputSerializer()": syntax error