from plomtask.processes import Process, ProcessStep, ProcessStepsNode
from plomtask.conditions import Condition
from plomtask.todos import Todo
-from plomtask.db import BaseModel
TEMPLATES_DIR = 'templates'
def ctx_to_json(ctx: dict[str, object]) -> str:
"""Render ctx into JSON string."""
def walk_ctx(node: object) -> Any:
- if isinstance(node, BaseModel):
+ if hasattr(node, 'as_dict_into_reference'):
+ if hasattr(node, 'id_') and node.id_ is not None:
+ return node.as_dict_into_reference(library)
+ if hasattr(node, 'as_dict'):
return node.as_dict
if isinstance(node, (list, tuple)):
return [walk_ctx(x) for x in node]
if isinstance(node, HandledException):
return str(node)
return node
+ library: dict[str, dict[str | int, object]] = {}
for k, v in ctx.items():
ctx[k] = walk_ctx(v)
+ ctx['_library'] = library
return json_dumps(ctx)
def render(self, ctx: dict[str, object], tmpl_name: str = '') -> str:
tmpl_name: str,
code: int = 200
) -> None:
- """Send HTML as proper HTTP response."""
+ """Send ctx as proper HTTP response."""
body = self.server.render(ctx, tmpl_name)
self.send_response(code)
for header_tuple in self.server.headers: