Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Commit

Permalink
Add edit support, close #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliix42 committed Dec 11, 2015
1 parent 561e26c commit d4d772e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tdo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def main(argv=sys.argv):
if ret_val[1]:
# if there were changes, save them
todolist.save(ret_val[0])
elif argv[1] == 'edit':
# tdo edit x - edit task no. x
if len(argv) < 3:
print('Please enter a task ID!')
else:
ret_val = todolist.edit(todos, argv[2])

if ret_val[1]:
# save changes, if there are any
todolist.save(ret_val[0])
elif argv[1] == 'newlist':
# tdo newlist "name" -- create list "name"
if len(argv) < 3:
Expand Down
1 change: 1 addition & 0 deletions tdo/todolist/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
tdo Lists all undone tasks, sorted by category.
tdo all Lists all tasks.
tdo add "task" [list] Add a task to a certain list or the default list.
tdo edit id Edit a task description.
tdo done id Mark tha task with the ID 'id' as done.
tdo newlist "name" Create a new list named 'name'
tdo remove "list" Delete the list 'list'
Expand Down
27 changes: 23 additions & 4 deletions tdo/todolist/listmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ def add(todolist, todoid, todoname, category='default'):
return todolist, True, todoid


def edit(todolist, task_id):
found = False
changed = False
for category in todolist:
for item in todolist[category]:
if item == str(task_id):
found = True
print('Task #{num}: {content}'.format(
num=task_id, content=todolist[category][task_id][0]))
inp = input("Enter your new task description \
(leave blank for abort): ")
if inp != '':
todolist[category][task_id][0] = inp
changed = True

if not found:
print('There is no task with the ID {num}.'.format(num=task_id))
return todolist, False
else:
return todolist, changed


def done(todolist, task_id):
'''
Marks an item as done.
Expand All @@ -51,10 +73,7 @@ def done(todolist, task_id):
print('There is no task with the ID {num}.'.format(num=task_id))
return todolist, False
else:
if changed:
return todolist, True
else:
return todolist, False
return todolist, changed


def addlist(todolist, new_category):
Expand Down

0 comments on commit d4d772e

Please sign in to comment.