Ver código fonte

Add prompt for category

theenglishway (time) 6 anos atrás
pai
commit
7506293369
3 arquivos alterados com 22 adições e 6 exclusões
  1. 21 4
      planner/cli.py
  2. 0 1
      planner/models/items.py
  3. 1 1
      planner/validator.py

+ 21 - 4
planner/cli.py

@@ -76,19 +76,36 @@ def new_sprint(ctx, name, description, milestone_id):
 def new_item(ctx, name, description, milestone_id=None, sprint_id=None, category=None):
     """Add a new sprint"""
     model = ctx.obj['model']
-    data = {}
+
     if not milestone_id and not sprint_id:
         parent_type = click.prompt('Related to [M]ilestone or [S]print ?', type=click.Choice(['m', 's']))
         if parent_type == 'm':
             milestone_id = click.prompt('Related milestone ID', type=int)
         elif parent_type == 's':
             sprint_id = click.prompt('Related sprint ID', type=int)
+
+    if not category:
+        choices = {
+            'limitation': 'l',
+            'feature': 'f',
+            'constraint': 'c',
+            'unknown': 'u'
+        }
+        category_choice = click.prompt(
+            'Which category ? ({})'.format(', '.join(choices.keys())),
+            type=click.Choice([v for v in choices.values()])
+        )
+
+        inv_choices = {v: k for k, v in choices.items()}
+        category = inv_choices[category_choice]
+
+    data = {'name': name, 'description': description, 'category': category}
+
     if milestone_id:
-        data = {'milestone_id': milestone_id}
+        data.update({'milestone_id': milestone_id})
     if sprint_id:
-        data = {'sprint_id': sprint_id}
+        data.update({'sprint_id': sprint_id})
 
-    data.update({'name': name, 'description': description, 'category': category})
     save_or_display_errors(model, data)
 
 @click.command()

+ 0 - 1
planner/models/items.py

@@ -1,6 +1,5 @@
 from dataclasses import dataclass, field
 from datetime import datetime
-from copy import deepcopy
 
 from .mixins import SchemaMixin, DbMixin
 from .milestones import Milestone

+ 1 - 1
planner/validator.py

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