diff --git a/alembic/versions/17946e7038d7_add_due_date_to_tasks.py b/alembic/versions/17946e7038d7_add_due_date_to_tasks.py new file mode 100644 index 0000000..37b2fe2 --- /dev/null +++ b/alembic/versions/17946e7038d7_add_due_date_to_tasks.py @@ -0,0 +1,32 @@ +"""add due date to tasks + +Revision ID: 17946e7038d7 +Revises: 719f2d1539c8 +Create Date: 2020-05-21 10:49:26.110397 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '17946e7038d7' +down_revision = '719f2d1539c8' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column( + 'tasks', + sa.Column( + 'due_at', + sa.DateTime, + nullable=True + ) + ) + + +def downgrade(): + with op.batch_alter_table('tasks') as tasks: + tasks.drop_column('due_at') diff --git a/requirements.txt b/requirements.txt index 3a79f41..4e1622c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ alembic sqlalchemy +dateparser diff --git a/src/pyelephant.py b/src/pyelephant.py index 3ff348b..d46f93f 100755 --- a/src/pyelephant.py +++ b/src/pyelephant.py @@ -3,14 +3,19 @@ import sqlalchemy as sa import sqlalchemy.ext.automap +import dateparser + ############################################################################### Base = sa.ext.automap.automap_base() Task = None ############################################################################### -def add(session: sa.orm.Session, title: str): - obj = Task(title=title) +def add(session: sa.orm.Session, title: str, due: str = None): + if due is not None: + due = dateparser.parse(due) + + obj = Task(title=title, due_at=due) session.add(obj) session.commit() show_by_obj(session, obj) @@ -32,7 +37,7 @@ def rm(session: sa.orm.Session, index: int): # ----------------------------------------------------------------------------- def show_by_obj(session: sa.orm.Session, obj: Task): - print(obj.id, obj.created_at, obj.active, obj.title) + print(obj.id, obj.created_at, obj.due_at, obj.active, obj.title) # ----------------------------------------------------------------------------- @@ -76,8 +81,9 @@ if __name__ == '__main__': subparsers = parser.add_subparsers() add_parser = subparsers.add_parser('add') - add_parser.set_defaults(func=add) + add_parser.set_defaults(func=add, due=None) add_parser.add_argument("title", type=str) + add_parser.add_argument("--due", type=str) done_parser = subparsers.add_parser('done') done_parser.set_defaults(func=done)