Re: FSSession newbie problem
--- In zope@egroups.com, Marcello Lupo <lupo@a...> wrote:
and macically i obtain the same error. this is the code i used: <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless>
<dtml-call "FSSession['carrello'].update(REQUEST.form)">
I have tried your code with 'cart' everywhere, and it worked just fine. Can you print out the form variables? Are all the statements inside the same DTML file? It really works fine. Also, make sure that FSSession is in a parent folder of your DTML method. (Root folder is usually a good idea.) Is your machine cookie-enabled? ==================================================== <dtml-var standard_html_header> <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless> <dtml-call "FSSession['cart'].update(REQUEST.form)"> <dtml-var "FSSession['cart']"> <dtml-var standard_html_footer> ==================================================== If you still have problems, you can try SQLSession or HappySession. For beginners I would recommend HappySession so you don't need to worry about the details of FSSession or SQLSession. Download HappySession from http://www.zope.org/Members/hungjunglu/Products/HappySession Add an HappySession instance in your Zope hierarchy. Then try: ==================================================== <dtml-var standard_html_header> <dtml-unless "SESSION.has_key('cart')"> <dtml-call "SESSION.set('cart',{})"> </dtml-unless> <dtml-call "SESSION['cart'].update(REQUEST.form)"> <dtml-var "SESSION['cart']"> <dtml-var standard_html_footer> ==================================================== regards, Hung Jung ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
Well... the statements are not in the same file but in two different files. This are the statements, the <dtml-call FSSession> is in the standard_html_header. Method list_products: <dtml-var standard_html_header> <dtml-unless "FSSession.has_key('carrello')"> <dtml-call "FSSession.set('carrello',{})"> </dtml-unless> <form action="aggiungi_prodotto" name="carrello" method="get" target="Carrello"> <input type="hidden" name="ID" value="<dtml-if "FSSession.has_key('ID')"><dtml-call "FSSession['ID']+1"><dtml-else>1</dtml-if>"> <input type="hidden" name="codice_famiglia" value="<dtml-var cod_prod>"> <input type="hidden" name="codice_prodotto" value="<dtml-var cod_ident>"> <input type="hidden" name="nome_prodotto" value="<dtml-var nome_prod_it>"> <input type="hidden" name="prezzo" value="<dtml-var prez_lire>"> <input type="hidden" name="quantita_prodotto" value="1"> <input type="image" name="acquista" value="acquista" src="/ecom/images/freccia2.jpg" border="0"> </form> <dtml-var standard-html-footer> Method aggiungi_prodotto: <dtml-var standard_html_header> <dtml-var "REQUEST.form"><br> ##### CHECK It prints out fine the form dictionary!! <dtml-in "REQUEST.form.items()"> <dtml-var sequence-item> </dtml-in> ##### CHECK It prints out fine the form variable!! <dtml-call "FSSession['carrello'].update(REQUEST.form)"> <br> <dtml-var ID> <dtml-var codice_famiglia> <dtml-var codice_prodotto> <dtml-var nome_prodotto> <dtml-var prezzo> <dtml-var quantita_prodotto> #### Them works fine!! <br> <dtml-var "FSSession('carrello')"><br> #### It prints out "None" <dtml-var standard_html_footer> The FSSession is in the same folder of my two methods, may be this a problem? I tried out the code in a single page and it works fine if you limit to create the variable 'carrello' in the FSSession. I checked the session file and it contains : ------cut here---- (dp1 S'carrello' p2 (ds. ---- cut here------ The problem is when i try to update the variable 'carrello' with something. I tryed the code you gave to me and it works so i think that the problem is that i initialize the variable in a method and update it in another one. Probably the second method point to a different session file than the first. Well thank you for help, for now i will make all in one method and of you have some ideas to solve it it will be appreciated. Bye. Marcello Hung Jung Lu wrote:
--- In zope@egroups.com, Marcello Lupo <lupo@a...> wrote:
and macically i obtain the same error. this is the code i used: <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless>
<dtml-call "FSSession['carrello'].update(REQUEST.form)">
I have tried your code with 'cart' everywhere, and it worked just fine. Can you print out the form variables? Are all the statements inside the same DTML file? It really works fine. Also, make sure that FSSession is in a parent folder of your DTML method. (Root folder is usually a good idea.) Is your machine cookie-enabled?
==================================================== <dtml-var standard_html_header> <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless> <dtml-call "FSSession['cart'].update(REQUEST.form)"> <dtml-var "FSSession['cart']"> <dtml-var standard_html_footer> ====================================================
If you still have problems, you can try SQLSession or HappySession. For beginners I would recommend HappySession so you don't need to worry about the details of FSSession or SQLSession.
Download HappySession from http://www.zope.org/Members/hungjunglu/Products/HappySession
Add an HappySession instance in your Zope hierarchy. Then try:
==================================================== <dtml-var standard_html_header> <dtml-unless "SESSION.has_key('cart')"> <dtml-call "SESSION.set('cart',{})"> </dtml-unless> <dtml-call "SESSION['cart'].update(REQUEST.form)"> <dtml-var "SESSION['cart']"> <dtml-var standard_html_footer> ====================================================
regards,
Hung Jung
________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
On Fri, 9 Jun 2000, Marcello Lupo wrote:
<dtml-var "FSSession('carrello')"><br> #### It prints out "None"
I supose you mean ...FSSession['carrello'] ..
The FSSession is in the same folder of my two methods, may be this a problem?
No it should not
one. Probably the second method point to a different session file than the first.
I also have <dtml-call FSSession> in my standard html header and I never had problems. I will try a few tests when I return. Please keep me posted if you continue having troubles. Pavlos
Hi, Yes the problem was the () indeed of []. And i think because i was calling another time an FSSession in the second page starting a new empty session too. Thanks for help. But i have other two questions: 1) Is necessary to call FSSession in every document of the site or is sufficient on the first page (home page of the e-com for example)? Becouse i noticed (obviously) that every time it open a file the HD. And i think this is a problem because every time it initialize a new session passing the new cookie to the Browser (i think). 2) How may i change the value of an element in a dictionary contained in FSSession? Example: I have the object 'carrello' as in the examples before that contain a dictionary passed to it from the form. I store the quantity of the item ordered in the value 'quantita_prodotto' in the object 'carrello'. If a user add another piece of that item i need to update the 'quantita_prodotto' summing to it the new item. I think this is possible but i ignore the syntax to do this. Thank you for help. Hung Jung Lu wrote:
--- In zope@egroups.com, Marcello Lupo <lupo@a...> wrote:
and macically i obtain the same error. this is the code i used: <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless>
<dtml-call "FSSession['carrello'].update(REQUEST.form)">
I have tried your code with 'cart' everywhere, and it worked just fine. Can you print out the form variables? Are all the statements inside the same DTML file? It really works fine. Also, make sure that FSSession is in a parent folder of your DTML method. (Root folder is usually a good idea.) Is your machine cookie-enabled?
==================================================== <dtml-var standard_html_header> <dtml-call FSSession> <dtml-unless "FSSession.has_key('cart')"> <dtml-call "FSSession.set('cart',{})"> </dtml-unless> <dtml-call "FSSession['cart'].update(REQUEST.form)"> <dtml-var "FSSession['cart']"> <dtml-var standard_html_footer> ====================================================
If you still have problems, you can try SQLSession or HappySession. For beginners I would recommend HappySession so you don't need to worry about the details of FSSession or SQLSession.
Download HappySession from http://www.zope.org/Members/hungjunglu/Products/HappySession
Add an HappySession instance in your Zope hierarchy. Then try:
==================================================== <dtml-var standard_html_header> <dtml-unless "SESSION.has_key('cart')"> <dtml-call "SESSION.set('cart',{})"> </dtml-unless> <dtml-call "SESSION['cart'].update(REQUEST.form)"> <dtml-var "SESSION['cart']"> <dtml-var standard_html_footer> ====================================================
regards,
Hung Jung
________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
On Fri, 9 Jun 2000, Marcello Lupo wrote:
1) Is necessary to call FSSession in every document of the site or is sufficient on the first page (home page of the e-com for example)? Becouse i noticed (obviously) that every time it open a file the HD. And i think this is a problem because every time it initialize a new session passing the new cookie to the Browser (i think).
Yes it is neccessary beacuse HTTP is stateless. It will only start a new session if FSSession cannot find a valid UID either through a cookie or a FORM or as part of te URL
2) How may i change the value of an element in a dictionary contained in FSSession?
Example: I have the object 'carrello' as in the examples before that contain a dictionary passed to it from the form. I store the quantity of the item ordered in the value 'quantita_prodotto' in the object 'carrello'. If a user add another piece of that item i need to update the 'quantita_prodotto' summing to it the new item. I think this is possible but i ignore the syntax to do this.
As you descripe in your example carrello is a dictinory. So one way is to make quantitita_prodotto a list and append to it. Something like <untested> <dtml-if "FSSession['carrillo'].has_key('quantita_prodotto')"> <dtml-call "FSSession['carrillo']['quatita_prodotto'].append(REQUEST.form['quatita_prodotto'])"> <dtml-else> <!-- need to fake the = sign which cannot be used in DTML expr--> <dtml-call "FSSession['carrillo'].update({'quatita_prodotto':[]})"> </dtml-if> plus some more logic to check if the variables are empty/correct etc .. Pavlos
participants (3)
-
Hung Jung Lu -
Marcello Lupo -
Pavlos Christoforou