redis_sessions.py, thanks Niphlod
This commit is contained in:
@@ -94,11 +94,11 @@ class SessionSetDb(SessionSet):
|
||||
"""Return list of SessionDb instances for existing sessions."""
|
||||
sessions = []
|
||||
tablename = 'web2py_session'
|
||||
if request.application:
|
||||
tablename = 'web2py_session_' + request.application
|
||||
if tablename in db:
|
||||
for row in db(db[tablename].id > 0).select():
|
||||
sessions.append(SessionDb(row))
|
||||
from gluon import current
|
||||
(record_id_name, table, record_id, unique_key) = \
|
||||
current.response._dbtable_and_field
|
||||
for row in table._db(table.id > 0).select():
|
||||
sessions.append(SessionDb(row))
|
||||
return sessions
|
||||
|
||||
|
||||
@@ -121,8 +121,11 @@ class SessionDb(object):
|
||||
self.row = row
|
||||
|
||||
def delete(self):
|
||||
from gluon import current
|
||||
(record_id_name, table, record_id, unique_key) = \
|
||||
current.response._dbtable_and_field
|
||||
self.row.delete_record()
|
||||
db.commit()
|
||||
table._db.commit()
|
||||
|
||||
def get(self):
|
||||
session = Storage()
|
||||
@@ -130,7 +133,13 @@ class SessionDb(object):
|
||||
return session
|
||||
|
||||
def last_visit_default(self):
|
||||
return self.row.modified_datetime
|
||||
if isinstance(self.row.modified_datetime, datetime.datetime):
|
||||
return self.row.modified_datetime
|
||||
else:
|
||||
try:
|
||||
return datetime.datetime.strptime(self.row.modified_datetime, '%Y-%m-%d %H:%M:%S.%f')
|
||||
except:
|
||||
print 'failed to retrieve last modified time (value: %s)' % self.row.modified_datetime
|
||||
|
||||
def __str__(self):
|
||||
return self.row.unique_key
|
||||
|
||||
Reference in New Issue
Block a user