Przeglądaj źródła

Add category to item

theenglishway (time) 6 lat temu
rodzic
commit
40bbd5a431
3 zmienionych plików z 48 dodań i 6 usunięć
  1. 3 3
      planner/cli.py
  2. 45 2
      planner/models/items.py
  3. 0 1
      planner/validator.py

+ 3 - 3
planner/cli.py

@@ -71,8 +71,9 @@ def new_sprint(ctx, name, description, milestone_id):
 @click.option('--description', prompt='Item description')
 @click.option('--milestone_id', type=int)
 @click.option('--sprint_id', type=int)
+@click.option('--category', type=str)
 @click.pass_context
-def new_item(ctx, name, description, milestone_id=None, sprint_id=None):
+def new_item(ctx, name, description, milestone_id=None, sprint_id=None, category=None):
     """Add a new sprint"""
     model = ctx.obj['model']
     data = {}
@@ -87,8 +88,7 @@ def new_item(ctx, name, description, milestone_id=None, sprint_id=None):
     if sprint_id:
         data = {'sprint_id': sprint_id}
 
-    data.update({'name': name, 'description': description})
-
+    data.update({'name': name, 'description': description, 'category': category})
     save_or_display_errors(model, data)
 
 @click.command()

+ 45 - 2
planner/models/items.py

@@ -12,6 +12,7 @@ class Item(SchemaMixin, DbMixin):
     document: dict
     name: str
     description: str
+    category: str
     milestone: Milestone
     sprint: Sprint
     date_added: datetime = None
@@ -30,13 +31,29 @@ class Item(SchemaMixin, DbMixin):
         description:
             required: true
             type: string
+        category:
+            required: true
+            type: string 
+            allowed: 
+                - feature
+                - limitation
+                - constraint
+                - unknown
         milestone_id:
             is_fk: milestone
+            excludes: sprint_id
+            required: true
         sprint_id:
             is_fk: sprint
+            excludes: milestone_id
+            required: true
         date_added:
             type: datetime
             default_setter: utcnow
+        date_expected:
+            type: date
+        date_started:
+            type: date
     """
 
     @classmethod
@@ -44,10 +61,36 @@ class Item(SchemaMixin, DbMixin):
         kwargs = deepcopy(document)
         milestone = Milestone.fetch(kwargs.pop('milestone_id', None))
         sprint = Sprint.fetch(kwargs.pop('sprint_id', None))
-        return cls(document=document, milestone=milestone, sprint=sprint, **kwargs)
+
+        category_to_kls = {
+            'feature': Feature,
+            'limitation': Limitation,
+            'constraint': Constraint,
+            'unknown': Unknown,
+        }
+
+        kls = category_to_kls[kwargs.get('category')]
+
+        return kls(document=document, milestone=milestone, sprint=sprint, **kwargs)
 
     def __repr__(self):
         return "{}(name='{}', milestone='{}')".format(self.__class__.__qualname__, self.name, repr(self.milestone))
 
     def __terminal__(self):
-        return f"Item : {self.name} ({self.sprint or self.milestone})"
+        return f"{self.__class__.__qualname__} : {self.name} ({self.sprint or self.milestone})"
+
+
+class Limitation(Item):
+    ...
+
+
+class Feature(Item):
+    ...
+
+
+class Constraint(Item):
+    ...
+
+
+class Unknown(Item):
+    ...

+ 0 - 1
planner/validator.py

@@ -11,7 +11,6 @@ class DbValidator(Validator):
     def _validate_is_fk(self, table_name, field, value):
         """ {'type': 'string'} """
         table = self.db.table(table_name)
-        print(table)
         if not table.get(doc_id=value):
             self._error(field, "No value found in {}".format(table_name))