Browse Source

Add proper support for comments

theenglishway (time) 6 years ago
parent
commit
d612606f4a
3 changed files with 23 additions and 11 deletions
  1. 16 1
      pyplanner/cli.py
  2. 4 7
      pyplanner/models/comments.py
  3. 3 3
      pyplanner/output.py

+ 16 - 1
pyplanner/cli.py

@@ -122,6 +122,21 @@ def new(ctx, **data):
         click.echo(Term.failure(e.args[0]))
 
 
+@comment.command('new')
+@click.option('--text', prompt='Text')
+@click.option('--item_id', prompt='ID of the item to add comment to')
+@click.pass_context
+def new_comment(ctx, **data):
+    """Add new content"""
+    model = ctx.obj['model']
+    db = ctx.obj['db']
+    try:
+        instance = db.create(model, data)
+        click.echo(Term.success(instance))
+    except ValueError as e:
+        click.echo(Term.failure(e.args[0]))
+
+
 @click.command('list')
 @click.pass_context
 def list(ctx):
@@ -134,7 +149,7 @@ def list(ctx):
         click.echo(output.output_data(i))
 
 
-for group in [milestone, sprint, item, comment]:
+for group in [milestone, sprint, item]:
     for command in [new, list]:
         group.add_command(command)
 

+ 4 - 7
pyplanner/models/comments.py

@@ -6,18 +6,15 @@ from pydantic import BaseModel
 
 
 class SchemaComment(BaseModel):
-    name: str
-    description: str
-    type: str
+    text: str
     uuid: str
 
-    milestone_id: int
-    sprint_id: int
+    item_id: int
 
-    priority: str
-    length: str
 
 class Comment(SQLABase, Base):
+    _schema = SchemaComment
+
     __tablename__ = 'comments'
     id = Column(Integer, primary_key=True)
 

+ 3 - 3
pyplanner/output.py

@@ -15,11 +15,11 @@ class TerminalOutput:
     {%- for item in obj.items %}
       {{ output(item) }}
     {%- endfor %}""",
-            Item: """{{ obj.type_term }} {{ Term.uuid(obj.short_uuid) }} # {{ obj.name }} ({{ obj.priority }}, {{ obj.length }})
+            Item: """{{ Term.bold(obj.type) }} {{ Term.uuid(obj.short_uuid) }} # {{ obj.name }} ({{ obj.priority }}, {{ obj.length }})
     {%- for comment in obj.comments %}
-      {{ comment.as_term }}
+      {{ output(comment) }}
     {%- endfor %}""",
-            Comment: """{{ obj.text }} {{ Term.uuid(obj.short_uuid) }}"""
+            Comment: """{{ Term.bold('Comment') }} {{ Term.uuid(obj.short_uuid) }} '{{ obj.text }}'"""
         }
         self.templates.update({
             subclass: self.templates[Item] for subclass in [Feature, Limitation, Unknown, Constraint]