From c14a139c1f317867cea0275cd0868efe83696220 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:25:22 +0200 Subject: [PATCH] add comment pydantic schema --- lib/galaxy/model/__init__.py | 5 +++ lib/galaxy/schema/workflow/comments.py | 62 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 lib/galaxy/schema/workflow/comments.py diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 6f0c508f4c7d..e99cbada7317 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -173,6 +173,7 @@ ) from galaxy.util.json import safe_loads from galaxy.util.sanitize_html import sanitize_html +from lib.galaxy.schema.workflow.comments import WorkflowCommentModel if TYPE_CHECKING: from galaxy.schema.invocation import InvocationMessageUnion @@ -8031,9 +8032,13 @@ def to_dict(self): if self.child_comments: comment_dict["child_comments"] = [comment.order_index for comment in self.child_comments] + WorkflowCommentModel(__root__=comment_dict) + return comment_dict def from_dict(dict): + WorkflowCommentModel(__root__=dict) + comment = WorkflowComment() comment.order_index = dict.get("id", 0) comment.type = dict.get("type", "text") diff --git a/lib/galaxy/schema/workflow/comments.py b/lib/galaxy/schema/workflow/comments.py new file mode 100644 index 000000000000..08198f7bc4c5 --- /dev/null +++ b/lib/galaxy/schema/workflow/comments.py @@ -0,0 +1,62 @@ +from typing import ( + List, + Literal, + Optional, + Tuple, + Union, +) + +from pydantic import BaseModel + + +class BaseComment(BaseModel): + id: int + colour: Literal["none", "black", "blue" "turquoise", "green", "lime", "orange", "yellow", "red", "pink"] + position: Tuple[float, float] + size: Tuple[float, float] + + +class TextCommentData(BaseModel): + bold: Optional[bool] + italic: Optional[bool] + size: int + text: str + + +class TextComment(BaseComment): + type: Literal["text"] + data: TextCommentData + + +class MarkdownCommentData(BaseModel): + text: str + + +class MarkdownComment(BaseComment): + type: Literal["markdown"] + data: MarkdownCommentData + + +class FrameCommentData(BaseModel): + title: str + + +class FrameComment(BaseComment): + type: Literal["frame"] + data: FrameCommentData + child_comments: Optional[List[int]] + child_steps: Optional[List[int]] + + +class FreehandCommentData(BaseModel): + thickness: int + line: List[Tuple[float, float]] + + +class FreehandComment(BaseComment): + type: Literal["freehand"] + data: FreehandCommentData + + +class WorkflowCommentModel(BaseModel): + __root__: Union[TextComment, MarkdownComment, FrameComment, FreehandComment]