[Zope] Determining user from session object - who is logged in?
Gaute Amundsen
gaute at div.org
Wed Oct 12 13:32:21 EDT 2005
I thought the place to start wold be: /temp_folder/session_data/
I have built a small little thing to play with the contents of that.
External method and script below.
However I have not been able to figure out a way to connect these sessions
with "logged in users".
I suppose I could make some add/remove actions to log the data somewhere, and
then get it from there, but there has to be some more direct way...
Any ideas anyone?
Gaute.
------
def CurrentSessions(self):
root = self.getPhysicalRoot()
session_data = root.restrictedTraverse('/temp_folder/session_data')
return session_data.items()
--------
## Script (Python) "view_sessions"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
def timeSpan(secs):
# seconds -> hours, minutes og seconds
hours = int(secs/3600)
secs = secs % 3600
minutes = int(secs/60)
secs = int(secs % 60)
return "%02d:%02d:%02d" % (hours, minutes, secs)
print 'View session data'
# flush expired objects...?
session = context.session_data_manager.getSessionData()
session.set('This is','me')
data = container.CurrentSessions()
print str(len(data)) + ' objects'
for i in data:
last = i[1].getLastAccessed()
made = i[1].getCreated()
now = DateTime().timeTime()
print i[1].items()
print 'Made: '+DateTime(made).strftime('%Y-%m-%d %H:%M:%S')
#print 'Last: '+DateTime(last).strftime('%Y-%m-%d %H:%M:%S')
#print 'Now: '+DateTime(now).strftime('%Y-%m-%d %H:%M:%S')
print 'Used: ' + timeSpan(last - made)
print 'Idle: ' + timeSpan(now - last)
print ''
return printed
------
More information about the Zope
mailing list