Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

workflow_app_log_fields.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from flask_restx import Api, Namespace, fields
  2. from fields.end_user_fields import build_simple_end_user_model, simple_end_user_fields
  3. from fields.member_fields import build_simple_account_model, simple_account_fields
  4. from fields.workflow_run_fields import build_workflow_run_for_log_model, workflow_run_for_log_fields
  5. from libs.helper import TimestampField
  6. workflow_app_log_partial_fields = {
  7. "id": fields.String,
  8. "workflow_run": fields.Nested(workflow_run_for_log_fields, attribute="workflow_run", allow_null=True),
  9. "created_from": fields.String,
  10. "created_by_role": fields.String,
  11. "created_by_account": fields.Nested(simple_account_fields, attribute="created_by_account", allow_null=True),
  12. "created_by_end_user": fields.Nested(simple_end_user_fields, attribute="created_by_end_user", allow_null=True),
  13. "created_at": TimestampField,
  14. }
  15. def build_workflow_app_log_partial_model(api_or_ns: Api | Namespace):
  16. """Build the workflow app log partial model for the API or Namespace."""
  17. workflow_run_model = build_workflow_run_for_log_model(api_or_ns)
  18. simple_account_model = build_simple_account_model(api_or_ns)
  19. simple_end_user_model = build_simple_end_user_model(api_or_ns)
  20. copied_fields = workflow_app_log_partial_fields.copy()
  21. copied_fields["workflow_run"] = fields.Nested(workflow_run_model, attribute="workflow_run", allow_null=True)
  22. copied_fields["created_by_account"] = fields.Nested(
  23. simple_account_model, attribute="created_by_account", allow_null=True
  24. )
  25. copied_fields["created_by_end_user"] = fields.Nested(
  26. simple_end_user_model, attribute="created_by_end_user", allow_null=True
  27. )
  28. return api_or_ns.model("WorkflowAppLogPartial", copied_fields)
  29. workflow_app_log_pagination_fields = {
  30. "page": fields.Integer,
  31. "limit": fields.Integer,
  32. "total": fields.Integer,
  33. "has_more": fields.Boolean,
  34. "data": fields.List(fields.Nested(workflow_app_log_partial_fields)),
  35. }
  36. def build_workflow_app_log_pagination_model(api_or_ns: Api | Namespace):
  37. """Build the workflow app log pagination model for the API or Namespace."""
  38. # Build the nested partial model first
  39. workflow_app_log_partial_model = build_workflow_app_log_partial_model(api_or_ns)
  40. copied_fields = workflow_app_log_pagination_fields.copy()
  41. copied_fields["data"] = fields.List(fields.Nested(workflow_app_log_partial_model))
  42. return api_or_ns.model("WorkflowAppLogPagination", copied_fields)