The persistent variable
First: again apologizing for having mixed up the words "vice" and "wise". I truely felt like an idiot and a no-brain. I hope I did not insult anybody. Mea maxima culpa. The bacground for my message was my eagernes to try to contribute, even with my small abilities, to the zope community which I find great and impressive! That stupid word "vice", I must have gotten in my head from the TV-series Miami Vice, some years ago. To much TV is dangerous :-) Now to the problem: I have a long time been fighting to find and establish something that I think in your language is called a "persistent variable". This variable, I wanted to use to personalize a website. Further, as my programming knowledge is so severe, I was looking for an easy way to do this, i.e. something that in pseudo code would look like this: set variable A let A = 1 And then later use variable A like this: if A = 1 do something However, I did not find an easy way to do this. My next plan was then to use cookies: <dtml-call expr="RESPONSE.setCookie('guest', 'C')"> And this: <dtml-if expr="REQUEST.has_key('guest', 'C')"> <dtml-var site_map> </dtml-if> However this also did not work. It was as though my cookie disappeared. Chris Withers then supplied mit with the following help: "You could look in REQUEST.cookies to be more on the safe side. I wonder what path is being set on your cookies? '/' is always a safe bet to prevent wierdness like this." I have try to understand and togle with this, but maybe I still do not understand the concept of cookies and the REQUEST object. I still cannot make it work. However, now I just read Dieter Maurers message (Re: [Zope] Variables and SubFolders): "Unless you do special things (modifiy a persistent object or store something in a session object) Zope forgets everything about a request as soon as it has been completed. Read the Zope Book (on zope.org) to learn something about sessions. Look for "manage_changeProperties" to learn how to modify properties of persistent objects. My question is then: Is properties maybe the easiest way to establish some "persistent variable" to play with in zope? (Sessions will until some more time unfortunately be to advanced for me.) I have also on this topic received the following good advices: - "The users are able to customise certain aspects of my application then the preferences are stored in a MySql database. When the user logs in, the application checks their user id and password but also reads in their preferences. These are used to apply style sheets and other various bits of customisation." [Stephen Slack] - "hint : Don't get started too much on DTML. Use python-scripts for things like this, and ZPT for presentation." [Geir Bækholt] I know I should follow these advices, but until some more time, both Python, zpt and sql databases are unfortunately beyond my knowledge ;-) Kind regards Børge
On Fri, 5 Sep 2003 11:43:06 +0200 GMT Børge Kjeldstad asked the Zope mailinglist about the following:
However, I did not find an easy way to do this. My next plan was then to use cookies: <dtml-call expr="RESPONSE.setCookie('guest', 'C')"> And this: <dtml-if expr="REQUEST.has_key('guest', 'C')"> <dtml-var site_map> </dtml-if>
I now think i understand what you are trying to do. if you try the following : <dtml-if expr="REQUEST.get('guest')=='C'"> or, following Chris' advice: <dtml-if expr="REQUEST.cookies.get('guest')=='C'"> I think you can accomplish what you are after. REQUEST.has_key() will return you true or false dependant on whether the key exists in the Request, so you can check if the cookie exists(but not it's value) by doing REQUEST.has_key('guest') :) -- Geir Bækholt
Geir Bækholt wrote: if you try the following : <dtml-if expr="REQUEST.get('guest')=='C'"> or, following Chris' advice: <dtml-if expr="REQUEST.cookies.get('guest')=='C'"> I think you can accomplish what you are after. Hi Geir, and thank you for your advice! I tried both solutions, but I got the same problem now too. The cookie lasted only for the first page I visited. I cheked this out by including <dtml-var REQUEST> on my pages. On the first page I got this: cookies tree-s 'eJzTiFZ3hANPW/VYHU0ALlYElA' guest 'C' dtpref_cols '105' dtpref_rows '30' On the next page I got this: cookies dtpref_rows '30' dtpref_cols '105' tree-s 'eJzTiFZ3hANPW/VYHU0ALlYElA' The cookie is gone.. So maybe it is the browser that's having fun with me? Best! Børge
On Fri, 5 Sep 2003 16:28:37 +0200 GMT B Kjeldstad asked the Zope mailinglist about the following:
I tried both solutions, but I got the same problem now too. The cookie lasted only for the first page I visited. I cheked this out by including <dtml-var REQUEST> on my pages. The cookie is gone..
So maybe it is the browser that's having fun with me?
Does the cookie return when you re-visit the first page? perhaps you're actually only bitten by the cookie path? try (untested): RESPONSE.setCookie('guest','C',path='/') -- Geir Bækholt
Yes yes yes yes yes yes yes!!!! This seems to work :-) !!!! At least on the part of the site where I have tried it out. I am going to try it out on all the pages now. To answer your question: The cookie returned when I used the browser's "back" button. But when I used my own "back" button (made with <form action> methods) the cookie was gone. Thank you indeed!! Børge Geir Bækholt wrote: Does the cookie return when you re-visit the first page? perhaps you're actually only bitten by the cookie path? try (untested): RESPONSE.setCookie('guest','C',path='/') -- Geir Bækholt
Børge Kjeldstad wrote:
My question is then: Is properties maybe the easiest way to establish some "persistent variable" to play with in zope? (Sessions will until some more time unfortunately be to advanced for me.)
Given the context you've supplied by using words such as "Guest", I'd suggest sessions are the way to go.
are stored in a MySql database. When the user logs in, the application checks their user id and password
How is this done?
I know I should follow these advices, but until some more time, both Python, zpt and sql databases are unfortunately beyond my knowledge ;-)
Python and ZPT are much easier than DTML, you have been warned... Chris
participants (4)
-
B Kjeldstad -
Børge Kjeldstad -
Chris Withers -
Geir Bækholt