harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4357harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4357PSEUDOCODE TASK
Goal
MODULE: sitetree/models.py
CLASS Tree ATTRIBUTES id: int or None // auto-generated on first save alias: str CLASS ATTRIBUTES _store: list of Tree _next_id: int METHODS init(alias: str, id: int|None = None) set self.alias = alias set self.id = id save() if self.id is None: // creating new Tree if exists t in Tree._store where t.alias == self.alias: raise Exception self.id = Tree._next_id Tree._next_id += 1 append self to Tree._store else: // updating existing Tree if exists t in Tree._store where t.id != self.id and t.alias == self.alias: raise Exception // update existing record in Tree._store with self str() -> str return self.alias get_title() -> str return self.alias
CLASS TreeItem ATTRIBUTES id: int or None // auto-generated on first save tree: Tree alias: str or None title: str or None parent: TreeItem or None sort_order: int or None CLASS ATTRIBUTES _store: list of TreeItem _next_id: int METHODS init(tree: Tree, alias: str|None = None, title: str|None = None, parent: TreeItem|None = None, sort_order: int|None = None, id: int|None = None) set self.tree = tree set self.alias = alias set self.title = title set self.parent = parent set self.sort_order = sort_order set self.id = id save() // Enforce alias uniqueness within the same tree if self.alias is not None: for item in TreeItem._store: if item is not self and item.tree == self.tree and item.alias == self.alias and item.alias is not None: raise Exception // Break self-reference if present if self.parent is self: self.parent = None // Assign ID if first save if self.id is None: self.id = TreeItem._next_id TreeItem._next_id += 1 append self to TreeItem._store // sort_order semantics if self.sort_order is None or self.sort_order == 0: self.sort_order = self.id str() -> str return self.title
IN-MEMORY PERSISTENCE DETAILS
Tests behavior mapping (to be satisfied by implementation)
DELIVERABLE