RE: [Zope] How can I store session data to db on login/logoff events ?
Thanks Dieter, it's work. But i have a problem with this: When I ran the test python script (see below) in Zope or I called the url directly from the browser , I got an error: Error Type: KeyError Error Value: 'SESSION' ##### Python test script ####### from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE session = request.SESSION session.set('VAR',99) This is the simple external event handler script ############ external module to catch session changes ################### def onSessionStart(item, container): from logging import getLogger request = container.REQUEST user = request.AUTHENTICATED_USER.getUserName() LOG = getLogger('DEMO') session = request.SESSION LOG.info( "Item data: %s" % item ) LOG.info( "Request data: %s" % request ) LOG.info( "Session data: %s" % session ) And in the event.log I can see this error: ############# event.log ################################### 2006-10-12T06:31:30 INFO DEMO Item data: id: 11606310900239978636, token: 88659718A2jNi4M24hE, content keys: [] ------ 2006-10-12T06:31:30 INFO DEMO Request data: <h3>form (..) <th>AUTHENTICATED_USER</th><td><SpecialUser 'Anonymous User'></td></tr><tr valign="top" align="left"><th> (...) SESSION</th><td>id: 1160631090023997863 6, token: 88659718A2jNi4M24hE, content keys: []</td></tr><tr valign="top" align="left"><th> (...) ------ 2006-10-12T06:31:30 INFO DEMO Session data: id: 11606310900239978636, token: 88659718A2jNi4M24hE, content keys: [] ------ 2006-10-12T06:31:30 ERROR Zope.SiteErrorLog http://xxx.xx.xxx.xxx:8080/startdemo/test Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Shared.DC.Scripts.Bindings, line 313, in __call__ Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec Module Products.PythonScripts.PythonScript, line 326, in _exec Module None, line 5, in test - <PythonScript at /startdemo/test> - Line 5 Module ZPublisher.HTTPRequest, line 1231, in __getattr__ Module ZPublisher.HTTPRequest, line 1182, in get KeyError: 'SESSION' What do I wrong? -----Original Message----- From: Dieter Maurer [mailto:dieter@handshake.de] Sent: Wednesday, October 11, 2006 8:43 PM To: Pletli Antal Cc: zope@zope.org Subject: Re: [Zope] How can I store session data to db on login/logoff events ? Pletli Antal wrote at 2006-10-11 15:19 +0200:
... How can I retrieve the user SESSION data when the items are created or deleted from the transient object container?
The "Transient Object Container" (that's the session container) has too scripts for this. You configure them in Zope's configuration file. -- Dieter
Am Donnerstag, 12. Oktober 2006 08:50 schrieb Pletli Antal:
Thanks Dieter, it's work.
But i have a problem with this:
When I ran the test python script (see below) in Zope or I called the url directly from the browser , I got an error:
Error Type: KeyError Error Value: 'SESSION'
we've seen this problem regulary, and work around it like so: def getSession(self): """ """ try: session = request.SESSION except KeyError: session = self.session_data_manager.getSessionData() return session Cheers, Sascha -- Lalisio GmbH www.lalisio.com Puschkinstraße 1 fon +49-(0)361/541 43 80 99084 Erfurt fax +49-(0)361/541 43 79 kontakt@lalisio.com +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AKTUELLER HINWEIS (Oktober 2006) Wussten Sie schon, dass Lalisio ab sofort den Dokumentenlieferdienst CISTI in seine Literatursuchmaschine einbindet? Sobald Sie über unsere Literatursuchmaschine in den Datenbanken Ingenta oder Projekt MUSE relevante Artikel finden, können Sie die bibliographischen Daten per Mausklick an CISTI übermitteln und Kopien der Artikel bestellen. Testen Sie unser Angebot unter www.lalisio.com! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Pletli Antal wrote at 2006-10-12 08:50 +0200:
But i have a problem with this:
When I ran the test python script (see below) in Zope or I called the url directly from the browser , I got an error:
Error Type: KeyError Error Value: 'SESSION'
The session object is passed as a parameter to the "script when session created" and "script when session deleted" scripts. -- Dieter
participants (3)
-
Dieter Maurer -
Pletli Antal -
Sascha Ottolski