From ab30d49729d231ad593d146bdfdcd68cc269a04e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 5 Oct 2011 22:56:10 +0200 Subject: tracking: Handle multiple matches in track_stop(). --- modules/tracking.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/modules/tracking.py b/modules/tracking.py index 72fbfc5..8995fdf 100644 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -185,17 +185,20 @@ class Module: msg = None try: session = Session() - consignment = session.query(Consignment).filter(or_(Consignment.code == code, Consignment.label == code)) + consignments = session.query(Consignment).filter(or_(Consignment.code == code, Consignment.label == code)) if nick: - consignment = consignment.filter(Consignment.nick == nick) - consignment = consignment.one() - code = consignment.code - for p in consignment.packages: - session.delete(p) - label = (' (%s)' % consignment.label) if consignment.label else '' - session.delete(consignment) + consignments = consignments.filter(Consignment.nick == nick) + deleted = [] + # we should have exactly one consignment, but need to handle cases when there are more + for consignment in consignments: + code = consignment.code + for p in consignment.packages: + session.delete(p) + label = (' (%s)' % consignment.label) if consignment.label else '' + deleted.append('\002%s\002%s' % (code.decode('utf8'), label)) + session.delete(consignment) session.commit() - msg = 'No longer tracking \002%s\002%s' % (code.decode('utf8'), label) + msg = 'No longer tracking %s' % ', '.join(deleted) except NoResultFound: msg = '\002%s\002 is not being tracked.' % code.decode('utf8') finally: -- cgit v1.2.3