summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-10-05 22:56:10 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-10-05 22:56:10 +0200
commitab30d49729d231ad593d146bdfdcd68cc269a04e (patch)
tree700742eed20445ea56315b08d4cca1eb5312e609
parentb6d7daf253436efba02f5e302afbfa432a57e542 (diff)
tracking: Handle multiple matches in track_stop().
-rw-r--r--modules/tracking.py21
1 files changed, 12 insertions, 9 deletions
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: