Re: [Zope] CoreSessionTracking - looping over items
Please try to keep correspondence on the list. THis can't be done from DTML if you're using an internal session data container because DTML can't access attributes with a leading underscore. Either use an external session data container or use an external method. For instance, here's an external method that returns the number of session data objects in the internal session data container, along with some DTML that calls it. def numberOfDataObjects(session_data_manager): return len(session_data_manager._sdc) <dtml-var "numberOfDataObjects(session_data_manager)"> HTH, - C ----- Original Message ----- From: "Pawel Lewicki" <lewicki@provider.pl> To: "Chris McDonough" <chrism@digicool.com> Sent: Monday, July 23, 2001 1:58 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
You can loop over the session data object in a session data container. The session data container uses the Python mapping interface.
There is an "internal" session data container if you're using the
default
RAM-based sessioning. It is the _sdc attribute of the session data manager. An external session data container is of course its own manageable Zope object.
See the SessioningInterfaces.py file for the interfaces associated with a session data container.
Hallo, Thanks a lot for your answer. I don't know if I don't understand some simple thing or it is a little bit more complicated. How to access sessions data? Would you give the simplest piece of dtml? I tried all variations of <dtml-in "SessionDataManager.sdc"> with and without ",_,'. How to access session objects from dtml? Of course I use the name of instance of SessionDataManager. Best regards,
Pawel
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl> Cc: <zope@zope.org> Sent: Monday, July 23, 2001 7:14 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
Please try to keep correspondence on the list.
THis can't be done from DTML if you're using an internal session data container because DTML can't access attributes with a leading underscore. Either use an external session data container or use an external method. For instance, here's an external method that returns the number of session data objects in the internal session data container, along with some DTML that calls it.
def numberOfDataObjects(session_data_manager): return len(session_data_manager._sdc)
<dtml-var "numberOfDataObjects(session_data_manager)">
I tried with python script but at zope says "Names starting with "_" are not allowed ", so I suppose it should be method defined in the external file. Is it enough to put .py file in Extensions directory with this piece of code? I've never tried external methods. The idea comes from ZopeBook and description of defining Brains to Z SQL Methods. It is the only reference I have on mind at the moment. As it doesn't work it should be something different. What should I do to make numberOfDataObjects visible to dtml document? And with the same solution is it possible to return the whole _sdc attribute as sliceable object to iterate with <dtml-in>? Pawel Lewicki
Hi Pawel, PythonScripts, like DTML, can't access attributes of objects which start with an underscore. Please read this HowTo in order to understand how to use external methods: http://www.zope.org/Documentation/How-To/ExternalMethods . As far as returning the whole _sdc object for use in DTML, do this: def getInternalSessionDataContainer(session_data_manager): return session_data_manager._sdc <dtml-with "getInternalSessionDataContainer(session_data_manager)"> ... </dtml-with> ... where session_data_manager is the session data manager you're using. HTH, - C ----- Original Message ----- From: "Pawel Lewicki" <lewicki@provider.pl> To: <zope@zope.org>; "Chris McDonough" <chrism@digicool.com> Sent: Monday, July 23, 2001 4:42 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl> Cc: <zope@zope.org> Sent: Monday, July 23, 2001 7:14 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
Please try to keep correspondence on the list.
THis can't be done from DTML if you're using an internal session data container because DTML can't access attributes with a leading
underscore.
Either use an external session data container or use an external method. For instance, here's an external method that returns the number of session data objects in the internal session data container, along with some DTML that calls it.
def numberOfDataObjects(session_data_manager): return len(session_data_manager._sdc)
<dtml-var "numberOfDataObjects(session_data_manager)">
I tried with python script but at zope says "Names starting with "_" are not allowed ", so I suppose it should be method defined in the external file. Is it enough to put .py file in Extensions directory with this piece of code? I've never tried external methods. The idea comes from ZopeBook and description of defining Brains to Z SQL Methods. It is the only reference I have on mind at the moment. As it doesn't work it should be something different. What should I do to make numberOfDataObjects visible to dtml document? And with the same solution is it possible to return the whole _sdc attribute as sliceable object to iterate with <dtml-in>?
Pawel Lewicki
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl>; <zope@zope.org> Sent: Monday, July 23, 2001 10:22 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
Hi Pawel,
PythonScripts, like DTML, can't access attributes of objects which start with an underscore. Please read this HowTo in order to understand how to use external methods: http://www.zope.org/Documentation/How-To/ExternalMethods .
As far as returning the whole _sdc object for use in DTML, do this:
def getInternalSessionDataContainer(session_data_manager): return session_data_manager._sdc
<dtml-with "getInternalSessionDataContainer(session_data_manager)"> ... </dtml-with>
... where session_data_manager is the session data manager you're using.
HTH,
Everything is working now, but I still don't know how to make a loop over sessions. I have a container. What should I put into <dtml-in> tag? Pawel
It depends what you want to do with each object, but for instance in order to show the last accessed time for each data object, do this: <dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> <dtml-var getLastAccessed> </dtml-in> See the SessioningInterfaces.py file for methods callable on session data objects. - C ----- Original Message ----- From: "Pawel Lewicki" <lewicki@provider.pl> To: <zope@zope.org>; "Chris McDonough" <chrism@digicool.com> Sent: Monday, July 23, 2001 6:49 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl>; <zope@zope.org> Sent: Monday, July 23, 2001 10:22 PM Subject: Re: [Zope] CoreSessionTracking - looping over items
Hi Pawel,
PythonScripts, like DTML, can't access attributes of objects which start with an underscore. Please read this HowTo in order to understand how
to
use external methods: http://www.zope.org/Documentation/How-To/ExternalMethods .
As far as returning the whole _sdc object for use in DTML, do this:
def getInternalSessionDataContainer(session_data_manager): return session_data_manager._sdc
<dtml-with "getInternalSessionDataContainer(session_data_manager)"> ... </dtml-with>
... where session_data_manager is the session data manager you're using.
HTH,
Everything is working now, but I still don't know how to make a loop over sessions. I have a container. What should I put into <dtml-in> tag?
Pawel
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl>; <zope@zope.org> Sent: Tuesday, July 24, 2001 12:01 AM Subject: Re: [Zope] CoreSessionTracking - looping over items
It depends what you want to do with each object, but for instance in order to show the last accessed time for each data object, do this:
<dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> <dtml-var getLastAccessed> </dtml-in>
Of course it was the first thing to try, but after simple: <dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> </dtml-in> I got zope error: Error Type: KeyError Error Value: 0 Pawel
OK, let's do it the hard way. ;-) None of this is tested, BTW. The session data container acts just like a dictionary, where the keys are the session id and the values are the session data container. <dtml-let sdc="getInternalSessionDataContainer(session_data_manager)"> <dtml-in "sdc.keys()"> <dtml-let key=sequence-item> <dtml-var "sdc[key].getLastAccessed()"><br> </dtml-let> </dtml-in> </dtml-let> Pawel Lewicki wrote:
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl>; <zope@zope.org> Sent: Tuesday, July 24, 2001 12:01 AM Subject: Re: [Zope] CoreSessionTracking - looping over items
It depends what you want to do with each object, but for instance in order to show the last accessed time for each data object, do this:
<dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> <dtml-var getLastAccessed> </dtml-in>
Of course it was the first thing to try, but after simple: <dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> </dtml-in>
I got zope error: Error Type: KeyError Error Value: 0
Pawel
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Scratch that sentence below where I say "teh values are the session data container", I meant "the values are the session data objects". Chris McDonough wrote:
OK, let's do it the hard way. ;-) None of this is tested, BTW. The session data container acts just like a dictionary, where the keys are the session id and the values are the session data container.
<dtml-let sdc="getInternalSessionDataContainer(session_data_manager)"> <dtml-in "sdc.keys()"> <dtml-let key=sequence-item> <dtml-var "sdc[key].getLastAccessed()"><br> </dtml-let> </dtml-in> </dtml-let>
Pawel Lewicki wrote:
----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: "Pawel Lewicki" <lewicki@provider.pl>; <zope@zope.org> Sent: Tuesday, July 24, 2001 12:01 AM Subject: Re: [Zope] CoreSessionTracking - looping over items
It depends what you want to do with each object, but for instance in order to show the last accessed time for each data object, do this:
<dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> <dtml-var getLastAccessed> </dtml-in>
Of course it was the first thing to try, but after simple: <dtml-in "getInternalSessionDataContainer(session_data_manager)" mapping> </dtml-in>
I got zope error: Error Type: KeyError Error Value: 0
Pawel
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Chris McDonough -
Pawel Lewicki