Skip to content

Commit

Permalink
Added ability to show opened tasks with or without closed.
Browse files Browse the repository at this point in the history
Two new commands 'show-all' and 'show-closed' were introdiced in the command line client.
  • Loading branch information
svetlyak40wt committed Feb 11, 2009
1 parent 888c955 commit e5c6a45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
15 changes: 12 additions & 3 deletions gtd.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, database):
self.gtd = gtdzen.GTD(database)

def run(self, cmd_name, args):
method = getattr(self, 'cmd_%s' % cmd_name, self.cmd_help)
method = getattr(self, 'cmd_%s' % cmd_name.replace('-', '_'), self.cmd_help)
return method(*args)

def cmd_add(self, title, priority = 1, tags = u''):
Expand All @@ -39,15 +39,24 @@ def cmd_add(self, title, priority = 1, tags = u''):
)
print u'Task %s was added' % task

def cmd_show(self, tags = u''):
def cmd_show(self, tags = u'', mode = 'open'):
with_tags, without_tags = _add_remove_tags(_parse_tags(tags))
tasks = self.gtd.getTasks(tags = with_tags, without_tags = without_tags)
tasks = self.gtd.getTasks(
tags = with_tags,
without_tags = without_tags,
show = mode)
if len(tasks) > 0:
for task in tasks:
print u'%d %s' % (task.id, task)
else:
print u'No tasks'

def cmd_show_closed(self, *args, **kwargs):
return self.cmd_show(mode = 'closed', *args, **kwargs)

def cmd_show_all(self, *args, **kwargs):
return self.cmd_show(mode = 'all', *args, **kwargs)

def cmd_update(self, task_ids, title = None, priority = None, tags = None):
if tags is not None:
add_tags, remove_tags = _add_remove_tags(_parse_tags(tags))
Expand Down
7 changes: 4 additions & 3 deletions gtdzen/__init__.py
Expand Up @@ -28,7 +28,8 @@ def addTask(self, title, note = None, tags = [], priority = 1):
def getTaskById(self, task_id):
return Task.query.get(task_id)

def getTasks(self, tags = [], without_tags = [], show_closed = False):
def getTasks(self, tags = [], without_tags = [], show = 'open'):
assert(show in ('all', 'open', 'closed'))
query = Task.query

tags = make_list(tags)
Expand All @@ -39,8 +40,8 @@ def getTasks(self, tags = [], without_tags = [], show_closed = False):
for tag in without_tags:
query = query.filter(not_(Task.tags.any(title = tag)))

if not show_closed:
query = query.filter_by(done = False)
if show != 'all':
query = query.filter_by(done = (show == 'closed'))

return query.all()

Expand Down
22 changes: 21 additions & 1 deletion tests/task_tests.py
Expand Up @@ -126,7 +126,7 @@ def testCloseTask(self):
self.assertEqual(1, len(tasks))
self.assertEqual(u'Second', tasks[0].title)

tasks = self.gtd.getTasks(show_closed = True)
tasks = self.gtd.getTasks(show = 'all')
self.assertEqual(2, len(tasks))
self.assertEqual(u'First', tasks[0].title)
self.assertEqual(u'Second', tasks[1].title)
Expand All @@ -140,3 +140,23 @@ def testGetTasksNegation(self):
self.assertEqual(task2, tasks[0])
self.assertEqual(task1, tasks[1])

def testShowModes(self):
self.gtd.closeTask(self.gtd.addTask(title = u'Closed', priority = 10).id)
self.gtd.addTask(title = u'Open', priority = 1)

# by default, only 'open' tasks
tasks = self.gtd.getTasks()
self.assertEqual(1, len(tasks))
self.assertEqual(u'Open', tasks[0].title)

tasks = self.gtd.getTasks(show = 'all')
self.assertEqual(2, len(tasks))
self.assertEqual(u'Closed', tasks[0].title)
self.assertEqual(u'Open', tasks[1].title)

tasks = self.gtd.getTasks(show = 'closed')
self.assertEqual(1, len(tasks))
self.assertEqual(u'Closed', tasks[0].title)

self.assertRaises(AssertionError, self.gtd.getTasks, show = 'bad-mode')

0 comments on commit e5c6a45

Please sign in to comment.