| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- from datetime import datetime
- from sqlalchemy import Column, DateTime, inspect
- from pydantic import ValidationError
- class Base:
- _schema = None
- date_created = Column(DateTime, default=datetime.utcnow)
- date_updated = Column(DateTime, onupdate=datetime.utcnow)
- @classmethod
- def validate(cls, data: dict):
- try:
- instance = cls._schema(**data)
- return True, instance
- except ValidationError as e:
- return False, e
- @classmethod
- def to_yaml(cls, representer, node):
- return representer.represent_data(node.attrs)
- @classmethod
- def from_yaml(cls, constructor, node):
- return cls()
- @classmethod
- def column_properties(cls):
- ins = inspect(cls)
- return [p.key for p in ins.iterate_properties if hasattr(p, 'columns')]
- @property
- def short_uuid(self):
- return self.uuid[:8]
- @property
- def attrs(self):
- return {
- k: getattr(self, k) for k in self.column_properties()
- }
- class BaseEnum:
- @classmethod
- def to_yaml(cls, representer, node):
- return representer.represent_scalar(
- node.value
- )
- @classmethod
- def from_yaml(cls, constructor, node):
- return cls(node)
- from .collections import Collection
- from .milestones import Milestone
- from .sprints import Sprint
- from .items import Item
- from .planned import (PlannedItem, PlannedItemType,
- Limitation, Constraint, Feature, Unknown,
- ItemPriority, Length)
- from .unplanned import (UnplannedItem, UnplannedItemType,
- Idea, Experimentation)
- from .comments import Comment
- from .tasks import Task
- from .index import UniversalIndex
- __all__ = [
- 'Collection',
- 'Milestone',
- 'Sprint',
- 'Item',
- 'PlannedItem', 'PlannedItemType',
- 'Limitation', 'Constraint', 'Feature', 'Unknown',
- 'ItemPriority', 'Length',
- 'UnplannedItem', 'UnplannedItemType',
- 'Experimentation', 'Idea',
- 'Comment',
- 'Task',
- 'UniversalIndex'
- ]
|