CoreSessionTracking's get looped in <dtml-in> does not work?
It seems that it is impossible to use <dtml-in> loop for data gleaned from CoreSessionTracking. I use CoreSessionTracking 0.8 quite extensively, and I only now stumbled accross this. Here's an example. -- This does not work. It gives Incorrect Attribute error for "fname". <dtml-in expr="data.get('writers')"> <dtml-var write_1_row> </dtml-in> WHERE: * writers is correctly stored dictionary (?) gleaned from ":records". I can do "<dtml-in expr="data.get('writers')"><dtml-var fname></dtml-in>, so the fname is being returned correctly. * write_1_row is Script (Python) containing just "output=string.strip(context.fname+' '+context.lname)", and some import and output statements. If I request data using ZSQL instead of CoreSessionTracking, everything works fine: -- This works: <dtml-in list_article_writers(m_id=m_id) <dtml-var write_1_row> </dtml-in> WHERE: * list_article_writers is ZSQL Method with "m_id:tokens" parameter, and the following content: SELECT fname, lname FROM members WHERE ...etc. * Is it just me? -- Milos Prudek
Milos Prudek wrote:
It seems that it is impossible to use <dtml-in> loop for data gleaned from CoreSessionTracking.
I use CoreSessionTracking 0.8 quite extensively, and I only now stumbled accross this. Here's an example.
-- This does not work. It gives Incorrect Attribute error for "fname". <dtml-in expr="data.get('writers')"> <dtml-var write_1_row> </dtml-in>
WHERE:
* writers is correctly stored dictionary (?) gleaned from ":records". I can do "<dtml-in expr="data.get('writers')"><dtml-var fname></dtml-in>, so the fname is being returned correctly.
It's a dictionary? Are you sure? If so, wouldn't you need: <dtml-with "data.get('writers')" mapping> <dtml-var fname> </dtml-with> CST can store just about any kind of object as a value in a session data object, and not all objects are sequences. What kind of object is 'writers'? -- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
It's a dictionary? Are you sure? If so, wouldn't you need:
Good question. It isn't. Sorry. It's a set of data received from form using ":records". I don't know what it's called in Python. It looks as follows: [fname: "Chris", lname: "McDonough", fname: "John", lname: "Malkovich"] You can iterate over it successfully: <dtml-in "data.get('writers')"><dtml-var fname></dtml-in>. Hypothesis: the above <dtml-in> puts "fname" into DTML namespace. Therefore it should be accessible from Python Script using "context.": <dtml-in "data.get('writers')"><dtml-var display></dtml-in> display (Python Script): a="<b>"+context.fname+"</b>" return a But it fails with Attribute Error. I do not comprehend why it fails. This looks like Level II Zope Zen, and it's more difficult than I thought. -- Milos Prudek
How about: <dtml-let "a=data.get('writers')"> <dtml-var "display(a)"> </dtml-let> Where display is: display (Python Script) arguments: data return data.get('fname') Milos Prudek wrote:
It's a dictionary? Are you sure? If so, wouldn't you need:
Good question. It isn't. Sorry. It's a set of data received from form using ":records". I don't know what it's called in Python. It looks as follows: [fname: "Chris", lname: "McDonough", fname: "John", lname: "Malkovich"]
You can iterate over it successfully: <dtml-in "data.get('writers')"><dtml-var fname></dtml-in>.
Hypothesis: the above <dtml-in> puts "fname" into DTML namespace. Therefore it should be accessible from Python Script using "context.":
<dtml-in "data.get('writers')"><dtml-var display></dtml-in>
display (Python Script): a="<b>"+context.fname+"</b>" return a
But it fails with Attribute Error. I do not comprehend why it fails.
This looks like Level II Zope Zen, and it's more difficult than I thought.
-- Milos Prudek
_______________________________________________ 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 )
-- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com """ Killing hundreds of birds with thousands of stones """
Dne pondělí 06 srpen 2001 15:32 jste napsal(a):
How about:
<dtml-let "a=data.get('writers')"> <dtml-var "display(a)"> </dtml-let>
Where display is:
display (Python Script) arguments: data
return data.get('fname')
I can't test it now... I'm at Zope 2.4 machine, and CoreSessionTracking 0.8 doesn't work with it. It looks good but I need to iterate using <dtml-in>... because I need a construct "<dtml-unless sequence-end>, </dtml-unless>" What you wrote does not look like iteration. The a variable receives a set of records... display Script is called with "a" parameter... fname is extracted from session data... but which fname, if there are many records? And what you wrote is a nested session extraction?? (first extract writers, then sub-extract fname?) You are right that when I pass the :records as a parameter I can iterate through it. However I cannot change values inside :records... unless I apply the patch suggested recently by Evan Simpson. If I do not want to patch, I need to convert :records into a list of tuples, and use it instead of records. Right? -- Milos Prudek
Milos Prudek wrote:
Dne pondìlí 06 srpen 2001 15:32 jste napsal(a):
How about:
<dtml-let "a=data.get('writers')"> <dtml-var "display(a)"> </dtml-let>
Where display is:
display (Python Script) arguments: data
return data.get('fname')
I can't test it now... I'm at Zope 2.4 machine, and CoreSessionTracking 0.8 doesn't work with it.
It will work with it if you delete the line "id = 'session_id_mgr'" in the SessioningInterfaces.py file. A new version will be out soon.
It looks good but I need to iterate using <dtml-in>... because I need a construct "<dtml-unless sequence-end>, </dtml-unless>"
Ummm.. ok.
What you wrote does not look like iteration. The a variable receives a set of records... display Script is called with "a" parameter... fname is extracted from session data... but which fname, if there are many records? And what you wrote is a nested session extraction?? (first extract writers, then sub-extract fname?)
OK, I've forgotten what the original problem was. ;-) But you may want to convert the record object out into a dictionary before you store it in CST, that way you can be sure of what you're operating against.
You are right that when I pass the :records as a parameter I can iterate through it. However I cannot change values inside :records... unless I apply the patch suggested recently by Evan Simpson. If I do not want to patch, I need to convert :records into a list of tuples, and use it instead of records. Right?
Or a different data structure that uses basic python types. I don't know about the patch that Evan suggested, but I do suggest you convert the record objects into bare python types before storing them. It'll make it easier to explain and maintain. -- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
Or a different data structure that uses basic python types. I don't know about the patch that Evan suggested, but I do suggest you convert the record objects into bare python types before storing them. It'll make it easier to explain and maintain.
That's it. It's sufficient information for me right now to continue hacking with Zope. Thank you very much for helping me with :records! -- Milos Prudek
participants (3)
-
Chris McDonough -
Chris McDonough -
Milos Prudek