|
|
@@ -1,74 +1,28 @@
|
|
|
from pyplanner.database import SQLABase
|
|
|
from pyplanner.models import Base, BaseEnum
|
|
|
-from sqlalchemy import Column, Integer, String, Text, ForeignKey
|
|
|
-from sqlalchemy.orm import relationship, backref
|
|
|
+from sqlalchemy import Column, Integer, String, Text
|
|
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
|
from pydantic import BaseModel
|
|
|
from enum import Enum
|
|
|
-from functools import total_ordering
|
|
|
|
|
|
|
|
|
-@total_ordering
|
|
|
-class Length(BaseEnum, Enum):
|
|
|
- MINUTES = 'mi'
|
|
|
- SEVERAL_MINUTES = 'mi+'
|
|
|
- HOURS = 'h'
|
|
|
- SEVERAL_HOURS = 'h+'
|
|
|
- DAYS = 'd'
|
|
|
- SEVERAL_DAYS = 'd+'
|
|
|
- WEEKS = 'w'
|
|
|
- SEVERAL_WEEKS = 'w+'
|
|
|
- MONTHS = 'mo'
|
|
|
- SEVERAL_MONTHS = 'mo+'
|
|
|
-
|
|
|
- def __add__(self, other):
|
|
|
- all_values = list(Length)
|
|
|
- if self == other and '+' not in self.value:
|
|
|
- return Length(f'{self.value}+')
|
|
|
- elif self.value in other.value:
|
|
|
- index = all_values.index(other)
|
|
|
- return all_values[index+1]
|
|
|
- elif other.value in self.value:
|
|
|
- index = all_values.index(self)
|
|
|
- return all_values[index+1]
|
|
|
- elif self > other:
|
|
|
- return self
|
|
|
- elif other > self:
|
|
|
- return other
|
|
|
- raise NotImplementedError()
|
|
|
-
|
|
|
- def __lt__(self, other):
|
|
|
- all_values = list(Length)
|
|
|
- return all_values.index(self) < all_values.index(other)
|
|
|
-
|
|
|
|
|
|
class ItemType(BaseEnum, Enum):
|
|
|
ITEM = 'none'
|
|
|
+
|
|
|
+ PLANNED = 'planned'
|
|
|
LIMITATION = 'lim'
|
|
|
FEATURE = 'feat'
|
|
|
CONSTRAINT = 'cons'
|
|
|
UNKNOWN = 'unk'
|
|
|
|
|
|
|
|
|
-class ItemPriority(BaseEnum, Enum):
|
|
|
- VERY_NOT_IMPORTANT = '--'
|
|
|
- NOT_IMPORTANT = '-'
|
|
|
- SO_SO = '='
|
|
|
- IMPORTANT = '+'
|
|
|
- VERY_IMPORTANT = '++'
|
|
|
-
|
|
|
-
|
|
|
class SchemaItem(BaseModel):
|
|
|
name: str
|
|
|
description: str
|
|
|
type: ItemType
|
|
|
uuid: str
|
|
|
|
|
|
- collection_id: int
|
|
|
-
|
|
|
- priority: ItemPriority = ItemPriority.SO_SO
|
|
|
- length: Length = Length.DAYS
|
|
|
-
|
|
|
|
|
|
class Item(SQLABase, Base):
|
|
|
_schema = SchemaItem
|
|
|
@@ -81,12 +35,6 @@ class Item(SQLABase, Base):
|
|
|
uuid = Column(String)
|
|
|
_type = Column(String)
|
|
|
|
|
|
- collection_id = Column(Integer, ForeignKey('collections.id'))
|
|
|
- collection = relationship('Collection', backref=backref('items'))
|
|
|
-
|
|
|
- _priority = Column(String)
|
|
|
- _length = Column(String)
|
|
|
-
|
|
|
@hybrid_property
|
|
|
def type(self):
|
|
|
return ItemType(self._type)
|
|
|
@@ -99,56 +47,8 @@ class Item(SQLABase, Base):
|
|
|
def type(cls):
|
|
|
return cls._type
|
|
|
|
|
|
- @hybrid_property
|
|
|
- def length(self):
|
|
|
- return Length(self._length)
|
|
|
-
|
|
|
- @length.setter
|
|
|
- def length(self, value):
|
|
|
- self._length = value.value
|
|
|
-
|
|
|
- @length.expression
|
|
|
- def length(cls):
|
|
|
- return cls._length
|
|
|
-
|
|
|
- @hybrid_property
|
|
|
- def priority(self):
|
|
|
- return ItemPriority(self._priority)
|
|
|
-
|
|
|
- @priority.setter
|
|
|
- def priority(self, value):
|
|
|
- self._priority = value.value
|
|
|
-
|
|
|
- @priority.expression
|
|
|
- def priority(cls):
|
|
|
- return cls._priority
|
|
|
-
|
|
|
__mapper_args__ = {
|
|
|
'polymorphic_on': _type,
|
|
|
'polymorphic_identity': ItemType.ITEM.value,
|
|
|
'with_polymorphic': '*'
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-class Limitation(Item):
|
|
|
- __mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.LIMITATION.value
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-class Feature(Item):
|
|
|
- __mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.FEATURE.value
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-class Constraint(Item):
|
|
|
- __mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.CONSTRAINT.value
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-class Unknown(Item):
|
|
|
- __mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.UNKNOWN.value
|
|
|
- }
|