|
|
@@ -5,10 +5,18 @@ from sqlalchemy import Column, Integer, String, ForeignKey
|
|
|
from sqlalchemy.orm import relationship, backref
|
|
|
from sqlalchemy.ext.hybrid import hybrid_property
|
|
|
|
|
|
-from .items import Item, SchemaItem, ItemType
|
|
|
+from .items import Item, SchemaItem
|
|
|
from . import BaseEnum
|
|
|
|
|
|
|
|
|
+class PlannedItemType(BaseEnum, Enum):
|
|
|
+ PLANNED = 'planned'
|
|
|
+ LIMITATION = 'lim'
|
|
|
+ FEATURE = 'feat'
|
|
|
+ CONSTRAINT = 'cons'
|
|
|
+ UNKNOWN = 'unk'
|
|
|
+
|
|
|
+
|
|
|
@total_ordering
|
|
|
class Length(BaseEnum, Enum):
|
|
|
MINUTES = 'mi'
|
|
|
@@ -52,6 +60,8 @@ class ItemPriority(BaseEnum, Enum):
|
|
|
|
|
|
|
|
|
class SchemaPlannedItem(SchemaItem):
|
|
|
+ type: PlannedItemType
|
|
|
+
|
|
|
collection_id: int
|
|
|
|
|
|
priority: ItemPriority = ItemPriority.SO_SO
|
|
|
@@ -59,8 +69,11 @@ class SchemaPlannedItem(SchemaItem):
|
|
|
|
|
|
|
|
|
class PlannedItem(Item):
|
|
|
+ _schema = SchemaPlannedItem
|
|
|
+
|
|
|
__tablename__ = 'planned_items'
|
|
|
id = Column(Integer, ForeignKey('items.id'), primary_key=True)
|
|
|
+ _type = Column(String)
|
|
|
|
|
|
collection_id = Column(Integer, ForeignKey('collections.id'))
|
|
|
collection = relationship('Collection', backref=backref('planned_items'))
|
|
|
@@ -69,9 +82,23 @@ class PlannedItem(Item):
|
|
|
_length = Column(String)
|
|
|
|
|
|
__mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.PLANNED.value
|
|
|
+ 'polymorphic_on': _type,
|
|
|
+ 'polymorphic_identity': PlannedItemType.PLANNED.value,
|
|
|
+ 'with_polymorphic': '*'
|
|
|
}
|
|
|
|
|
|
+ @hybrid_property
|
|
|
+ def type(self):
|
|
|
+ return PlannedItemType(self._type)
|
|
|
+
|
|
|
+ @type.setter
|
|
|
+ def type(self, value):
|
|
|
+ self._type = value.value
|
|
|
+
|
|
|
+ @type.expression
|
|
|
+ def type(cls):
|
|
|
+ return cls._type
|
|
|
+
|
|
|
@hybrid_property
|
|
|
def length(self):
|
|
|
return Length(self._length)
|
|
|
@@ -99,23 +126,23 @@ class PlannedItem(Item):
|
|
|
|
|
|
class Limitation(PlannedItem):
|
|
|
__mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.LIMITATION.value
|
|
|
+ 'polymorphic_identity': PlannedItemType.LIMITATION.value
|
|
|
}
|
|
|
|
|
|
|
|
|
class Feature(PlannedItem):
|
|
|
__mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.FEATURE.value
|
|
|
+ 'polymorphic_identity': PlannedItemType.FEATURE.value
|
|
|
}
|
|
|
|
|
|
|
|
|
class Constraint(PlannedItem):
|
|
|
__mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.CONSTRAINT.value
|
|
|
+ 'polymorphic_identity': PlannedItemType.CONSTRAINT.value
|
|
|
}
|
|
|
|
|
|
|
|
|
class Unknown(PlannedItem):
|
|
|
__mapper_args__ = {
|
|
|
- 'polymorphic_identity': ItemType.UNKNOWN.value
|
|
|
+ 'polymorphic_identity': PlannedItemType.UNKNOWN.value
|
|
|
}
|