from sqlite3 import Row
from datetime import datetime
from plomtask.db import DatabaseConnection
+from plomtask.exceptions import NotFoundException, BadFormatException
class Process:
"""Template for, and metadata for, Todos, and their arrangements."""
def __init__(self, id_: int | None) -> None:
- self.id_ = id_ if id_ != 0 else None # to avoid DB-confusing rowid=0
+ if (id_ is not None) and id_ < 1:
+ raise BadFormatException(f'illegal Process ID, must be >=1: {id_}')
+ self.id_ = id_
self.title = VersionedAttribute(self, 'title', 'UNNAMED')
self.description = VersionedAttribute(self, 'description', '')
self.effort = VersionedAttribute(self, 'effort', 1.0)
return list(processes.values())
@classmethod
- def by_id(cls, db_conn: DatabaseConnection,
- id_: int | None, create: bool = False) -> Process | None:
+ def by_id(cls, db_conn: DatabaseConnection, id_: int | None,
+ create: bool = False) -> Process:
"""Collect all Processes and their connected VersionedAttributes."""
process = None
for row in db_conn.exec('SELECT * FROM processes '
'WHERE id = ?', (id_,)):
process = cls(row[0])
break
- if create and not process:
+ if not process:
+ if not create:
+ raise NotFoundException(f'Process not found of id: {id_}')
process = Process(id_)
if process:
for row in db_conn.exec('SELECT * FROM process_titles '