Commit a9f29074 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge pull request #5 from mruwek/multi-pri

Allow multiple tasks to be prioritized at once
parents 2a9be13f 0593bfbd
......@@ -62,6 +62,14 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "(A) Foo\n")
self.assertEquals(self.errors, "")
def test_set_prio5(self):
command = PriorityCommand(["Foo", "2", "C"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Priority changed from A to C\n(C) Foo\nPriority set to C.\n(C) Bar\n")
self.assertEquals(self.errors, "")
def test_invalid1(self):
command = PriorityCommand(["99", "A"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -30,38 +30,43 @@ class PriorityCommand(Command):
if not super(PriorityCommand, self).execute():
return False
number = None
numbers = None
priority = None
try:
number = self.argument(0)
priority = self.argument(1)
todo = self.todolist.todo(number)
numbers = self.args[:-1]
priority = self.args[-1]
if is_valid_priority(priority):
old_priority = todo.priority()
self.todolist.set_priority(todo, priority)
if len(numbers) > 0:
todos = [self.todolist.todo(number) for number in numbers]
if old_priority and priority and old_priority != priority:
self.out("Priority changed from {} to {}".format(
old_priority, priority))
elif not old_priority:
self.out("Priority set to {}.".format(priority))
if is_valid_priority(priority):
for todo in todos:
old_priority = todo.priority()
self.todolist.set_priority(todo, priority)
self.out(self.printer.print_todo(todo))
if old_priority and priority and old_priority != priority:
self.out("Priority changed from {} to {}".format(
old_priority, priority))
elif not old_priority:
self.out("Priority set to {}.".format(priority))
self.out(self.printer.print_todo(todo))
else:
self.error("Invalid priority given.")
else:
self.error("Invalid priority given.")
except InvalidCommandArgument:
self.error(self.usage())
except (IndexError, InvalidCommandArgument):
self.error(self.usage())
except (InvalidTodoException):
if number and priority:
if len(numbers) > 0 and priority:
self.error( "Invalid todo number given.")
else:
self.error(self.usage())
def usage(self):
return """Synopsis: pri <NUMBER> <PRIORITY>"""
return """Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>"""
def help(self):
return """\
Sets the priority of todo the given number to the given priority.
Sets the priority of todo(s) the given number(s) to the given priority.
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment