Now Todo.remove can take multiple taskids to be removed instead of just one

This commit is contained in:
James Vega 2003-12-10 13:51:58 +00:00
parent c6d77bb923
commit 0c3c37b4ba
2 changed files with 47 additions and 12 deletions

View File

@ -211,7 +211,7 @@ class Todo(callbacks.Privmsg):
irc.reply(msg, '%s (Todo #%s added)' % (conf.replySuccess, todoId)) irc.reply(msg, '%s (Todo #%s added)' % (conf.replySuccess, todoId))
def remove(self, irc, msg, args): def remove(self, irc, msg, args):
"""<task id> """<task id> [<task id> ...]
Removes <task id> from your personal todo list. Removes <task id> from your personal todo list.
""" """
@ -220,18 +220,30 @@ class Todo(callbacks.Privmsg):
except KeyError: except KeyError:
irc.error(msg, conf.replyNotRegistered) irc.error(msg, conf.replyNotRegistered)
return return
taskid = privmsgs.getArgs(args) taskids = privmsgs.getArgs(args)
tasks = taskids.split()
#print 'Tasks: %s' % repr(tasks)
db = self.dbHandler.getDb() db = self.dbHandler.getDb()
cursor = db.cursor() cursor = db.cursor()
cursor.execute("""SELECT * FROM todo invalid = []
WHERE id = %s AND userid = %s for taskid in tasks:
AND active = 1""", taskid, id) cursor.execute("""SELECT * FROM todo
if cursor.rowcount == 0: WHERE id = %s AND userid = %s
irc.error(msg, 'None of your tasks match that id.') AND active = 1""", taskid, id)
return #print 'Rowcount: %s' % cursor.rowcount
cursor.execute("""UPDATE todo SET active = 0 WHERE id = %s""", taskid) if cursor.rowcount == 0:
db.commit() invalid.append(taskid)
irc.reply(msg, conf.replySuccess) #print 'Invalid tasks: %s' % repr(invalid)
if invalid:
irc.error(msg, 'No tasks were removed because the following '\
'tasks could not be removed: %s' % \
utils.commaAndify(invalid))
else:
for taskid in tasks:
cursor.execute("""UPDATE todo SET active = 0 WHERE id = %s""",
taskid)
db.commit()
irc.reply(msg, conf.replySuccess)
_sqlTrans = string.maketrans('*?', '%_') _sqlTrans = string.maketrans('*?', '%_')
def search(self, irc, msg, args): def search(self, irc, msg, args):

View File

@ -39,10 +39,14 @@ except ImportError:
if sqlite is not None: if sqlite is not None:
class TodoTestCase(PluginTestCase, PluginDocumentation): class TodoTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Todo', 'User') plugins = ('Todo', 'User')
_user1 = 'foo!bar@baz'
_user2 = 'bar!foo@baz'
def setUp(self): def setUp(self):
PluginTestCase.setUp(self) PluginTestCase.setUp(self)
# Create a valid user to use # Create a valid user to use
self.prefix = 'foo!bar@baz' self.prefix = self._user2
self.assertNotError('register testy oom')
self.prefix = self._user1
self.assertNotError('register tester moo') self.assertNotError('register tester moo')
def testTodo(self): def testTodo(self):
@ -77,9 +81,28 @@ if sqlite is not None:
self.assertNotError('todo add --priority=1000 fix all bugs') self.assertNotError('todo add --priority=1000 fix all bugs')
def testRemovetodo(self): def testRemovetodo(self):
self.nick = 'testy'
self.prefix = self._user2
self.assertNotError('todo add do something')
self.assertNotError('todo add do something else') self.assertNotError('todo add do something else')
self.assertNotError('todo add do something again')
self.assertNotError('todo remove 1') self.assertNotError('todo remove 1')
self.assertNotError('todo 1') self.assertNotError('todo 1')
self.nick = 'tester'
self.prefix = self._user1
self.assertNotError('todo add make something')
self.assertNotError('todo add make something else')
self.assertNotError('todo add make something again')
self.assertError('todo remove 2 4')
self.assertNotRegexp('todo 2', r'Inactive')
self.assertNotRegexp('todo 4', r'Inactive')
self.assertError('todo remove 2')
self.assertNotRegexp('todo 2', r'Inactive')
self.assertNotError('todo')
self.assertNotError('todo remove 4 5')
self.assertNotError('todo')
self.assertRegexp('todo 4', r'Inactive')
self.assertRegexp('todo 5', r'Inactive')
def testSearchtodo(self): def testSearchtodo(self):
self.assertNotError('todo add task number one') self.assertNotError('todo add task number one')