add comment pydantic schema

This commit is contained in:
Laila Los
2023-10-26 13:54:26 +02:00
parent 9453be342e
commit 3ca393ff1f
2 changed files with 67 additions and 0 deletions
+5
View File
@@ -173,6 +173,7 @@ from galaxy.util.hash_util import (
)
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 @@ class WorkflowComment(Base, RepresentById):
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")
+62
View File
@@ -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]