Explorar o código

Move "item" model into "planned"

theenglishway (time) %!s(int64=6) %!d(string=hai) anos
pai
achega
61d37491fb
Modificáronse 3 ficheiros con 127 adicións e 105 borrados
  1. 3 2
      pyplanner/models/__init__.py
  2. 3 103
      pyplanner/models/items.py
  3. 121 0
      pyplanner/models/planned.py

+ 3 - 2
pyplanner/models/__init__.py

@@ -47,8 +47,9 @@ class BaseEnum:
 from .collections import Collection
 from .milestones import Milestone
 from .sprints import Sprint
-from .items import (Item, Limitation, Constraint, Feature, Unknown,
-                    ItemType, ItemPriority, Length)
+from .items import Item, ItemType
+from .planned import (Limitation, Constraint, Feature, Unknown,
+                      ItemPriority, Length)
 from .comments import Comment
 
 

+ 3 - 103
pyplanner/models/items.py

@@ -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
-    }

+ 121 - 0
pyplanner/models/planned.py

@@ -0,0 +1,121 @@
+from enum import Enum
+from functools import total_ordering
+
+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 . import BaseEnum
+
+
+@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 ItemPriority(BaseEnum, Enum):
+    VERY_NOT_IMPORTANT = '--'
+    NOT_IMPORTANT = '-'
+    SO_SO = '='
+    IMPORTANT = '+'
+    VERY_IMPORTANT = '++'
+
+
+class SchemaPlannedItem(SchemaItem):
+    collection_id: int
+
+    priority: ItemPriority = ItemPriority.SO_SO
+    length: Length = Length.DAYS
+
+
+class PlannedItem(Item):
+    __tablename__ = 'planned_items'
+    id = Column(Integer, ForeignKey('items.id'), primary_key=True)
+
+    collection_id = Column(Integer, ForeignKey('collections.id'))
+    collection = relationship('Collection', backref=backref('planned_items'))
+
+    _priority = Column(String)
+    _length = Column(String)
+
+    __mapper_args__ = {
+        'polymorphic_identity': ItemType.PLANNED.value
+    }
+
+    @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
+
+
+class Limitation(PlannedItem):
+    __mapper_args__ = {
+        'polymorphic_identity': ItemType.LIMITATION.value
+    }
+
+
+class Feature(PlannedItem):
+    __mapper_args__ = {
+        'polymorphic_identity': ItemType.FEATURE.value
+    }
+
+
+class Constraint(PlannedItem):
+    __mapper_args__ = {
+        'polymorphic_identity': ItemType.CONSTRAINT.value
+    }
+
+
+class Unknown(PlannedItem):
+    __mapper_args__ = {
+        'polymorphic_identity': ItemType.UNKNOWN.value
+    }