X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FSessions.py;h=6a03068b81f5e96633264861ed979a2fef9d2cfe;hb=19d4a01ccf66af9e00914351b3eacd5fc880f988;hp=2414161e3c526946da994b575c33bc9f7745d259;hpb=286cdfc25f6ef8fd3e0ed59a175bcf801b14038a;p=plcapi.git diff --git a/PLC/Sessions.py b/PLC/Sessions.py index 2414161..6a03068 100644 --- a/PLC/Sessions.py +++ b/PLC/Sessions.py @@ -1,4 +1,3 @@ -# $Id# from types import StringTypes import random import base64 @@ -66,21 +65,29 @@ class Sessions(Table): """ def __init__(self, api, session_filter = None, expires = int(time.time())): - Table.__init__(self, api, Session) + Table.__init__(self, api, Session) sql = "SELECT %s FROM view_sessions WHERE True" % \ ", ".join(Session.fields) - if session_filter is not None: - if isinstance(session_filter, (list, tuple, set)): - # Separate the list into integers and strings + if session_filter is not None: + if isinstance(session_filter, (list, tuple, set)): + # Separate the list into integers and strings ints = filter(lambda x: isinstance(x, (int, long)), session_filter) strs = filter(lambda x: isinstance(x, StringTypes), session_filter) session_filter = Filter(Session.fields, {'person_id': ints, 'session_id': strs}) sql += " AND (%s) %s" % session_filter.sql(api, "OR") - elif isinstance(session_filter, dict): - session_filter = Filter(Session.fields, session_filter) - sql += " AND (%s) %s" % session_filter.sql(api, "AND") + elif isinstance(session_filter, dict): + session_filter = Filter(Session.fields, session_filter) + sql += " AND (%s) %s" % session_filter.sql(api, "AND") + elif isinstance(session_filter, (int, long)): + session_filter = Filter(Session.fields, {'person_id': session_filter}) + sql += " AND (%s) %s" % session_filter.sql(api, "AND") + elif isinstance(session_filter, StringTypes): + session_filter = Filter(Session.fields, {'session_id': session_filter}) + sql += " AND (%s) %s" % session_filter.sql(api, "AND") + else: + raise PLCInvalidArgument, "Wrong session filter"%session_filter if expires is not None: if expires >= 0: