summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2012-09-23 14:52:08 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2012-09-23 14:52:08 +0200
commit3e9165dc5436b911063605dc7c7fcc7412d34ad2 (patch)
tree5ec1ddc344e718aadb0665f66a71680f9b83f105 /modules
parent370c7671da693aeb3dce730694b4d0ea2e63c554 (diff)
Filter consignments by server to allow updating trackings not registered in a channel.
Diffstat (limited to 'modules')
-rw-r--r--modules/tracking.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index 86b59b7..1b06678 100644
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -24,6 +24,7 @@ class Consignment(Base):
__tablename__ = 'consignment'
id = Column(Integer, primary_key = True)
+ server = Column(String, nullable = False)
nick = Column(String, nullable = False)
channel = Column(String) # NULL for private
code = Column(String, nullable = False, unique = True)
@@ -34,7 +35,8 @@ class Consignment(Base):
packages = relation('Package', backref = 'consignment', primaryjoin = 'Package.consignment_id == Consignment.id')
- def __init__(self, nick, channel, type, code, label, added):
+ def __init__(self, server, nick, channel, type, code, label, added):
+ self.server = server
self.nick = nick
self.channel = channel
self.type = type
@@ -191,7 +193,7 @@ class Module:
msg = None
try:
session = Session()
- consignment = Consignment(nick, channel, type, code, label.decode('utf8'), datetime.datetime.utcnow())
+ consignment = Consignment(self.irc.factory.server, nick, channel, type, code, label.decode('utf8'), datetime.datetime.utcnow())
session.add(consignment)
session.commit()
msg = 'Now tracking \002%s\002.' % code
@@ -209,7 +211,8 @@ class Module:
msg = None
try:
session = Session()
- consignments = session.query(Consignment).filter(or_(Consignment.code == code, Consignment.label == code))
+ consignments = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server,
+ or_(Consignment.code == code, Consignment.label == code)))
if nick:
consignments = consignments.filter(Consignment.nick == nick)
deleted = []
@@ -233,7 +236,8 @@ class Module:
msg = []
try:
session = Session()
- consignments = session.query(Consignment).filter(or_(Consignment.code.like(code + '%'), Consignment.label.like((code + '%'))))
+ consignments = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server,
+ or_(Consignment.code.like(code + '%'), Consignment.label.like((code + '%')))))
if nick:
consignments = consignments.filter(Consignment.nick == nick)
results = []
@@ -288,7 +292,7 @@ class Module:
msg = None
try:
session = Session()
- consignment = session.query(Consignment).filter_by(code = code).filter_by(nick = nick).one()
+ consignment = session.query(Consignment).filter_by(server = server).filter_by(code = code).filter_by(nick = nick).one()
consignment.label = label.decode('utf8')
session.add(consignment)
session.commit()
@@ -302,7 +306,7 @@ class Module:
try:
session = Session()
trackings = []
- consignments = session.query(Consignment).filter_by(nick = nick)
+ consignments = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server, Consignment.nick == nick))
for row in consignments:
trackings.append(str(row))
if len(trackings):
@@ -319,7 +323,8 @@ class Module:
msg = []
try:
session = Session()
- consignments = session.query(Consignment).filter(or_(Consignment.code.like(code + '%'), Consignment.label.like(code+ '%')))
+ consignments = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server,
+ or_(Consignment.code.like(code + '%'), Consignment.label.like(code+ '%'))))
if nick:
consignments = consignments.filter(Consignment.nick == nick)
results = []
@@ -397,7 +402,7 @@ class Module:
def track_update(self, code, announce = False, propagate_error = False):
try:
session = Session()
- consignment = session.query(Consignment).filter(Consignment.code == code).one()
+ consignment = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server, Consignment.code == code)).one()
self.update_consignment(session, consignment, announce, propagate_error)
session.commit()
finally:
@@ -473,7 +478,8 @@ class Module:
def lc_callback(self):
try:
session = Session()
- consignments = session.query(Consignment).filter(Consignment.channel.in_(config.get(self.irc.factory.server, 'channels').split()))
+ consignments = session.query(Consignment).filter(and_(Consignment.server == self.irc.factory.server,
+ or_(Consignment.channel.in_(config.get(self.irc.factory.server, 'channels').split()), Consignment.Channel == None)))
for row in consignments:
self.update_consignment(session, row)
session.commit()