- Can't make the DTML example work ;-(
Hello, I tried the example you give about DTML (counter), but I get an error about the line that increments the variable. I don't understand why, as I followed exactly the given directions. Here is what I made: 1) create a 'counter' variable in the folder properties (id=counter, type=int, initial value=0) 2) The I added to the index_html method: <!--#call expr="counter=counter+1"--> Counter: <!--#var counter--> When I try to view the page, I get the following error: ================== Sorry, an error occurred.<p> <!-- Traceback (innermost last): File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 879, in publish_module File /usr/local/Zope/lib/python/ZPublisher/Publish.py, line 595, in publish (Info: /vitrine1/index_html/manage_edit) File /usr/local/Zope/lib/python/OFS/Document.py, line 261, in manage_edit (Object: index_html) File /usr/local/Zope/lib/python/DocumentTemplate/DT_String.py, line 372, in munge (Object: index_html) File /usr/local/Zope/lib/python/DocumentTemplate/DT_String.py, line 388, in cook (Object: index_html) File /usr/local/Zope/lib/python/DocumentTemplate/DT_String.py, line 239, in parse (Object: index_html) File /usr/local/Zope/lib/python/DocumentTemplate/DT_Var.py, line 318, in __init__ File /usr/local/Zope/lib/python/DocumentTemplate/DT_Util.py, line 321, in name_param (Info: ({'expr': 'counter=counter+1'}, 'call', 1, 'name')) File /usr/local/Zope/lib/python/DocumentTemplate/VSEval.py, line 170, in __init__ (Object: counter=counter+1) File "<string>", line 1 counter=counter+1 ^ SyntaxError: invalid syntax =================== Can anyone explain me what's wrong ? Thanks, Luc
Luc> <!--#call expr="counter=counter+1"--> Luc> Counter: <!--#var counter--> Luc> When I try to view the page, I get the following error: ... Luc> File /usr/local/Zope/lib/python/DocumentTemplate/VSEval.py, line 170, in __init__ Luc> (Object: counter=counter+1) Luc> File "<string>", line 1 Luc> counter=counter+1 Luc> ^ Luc> SyntaxError: invalid syntax Luc> =================== I'm not sure what example you're referring to, or precisely what the solution is, but it looks to me like you're putting a statement (counter=counter+1) where an expression (e.g., counter+1) is required. Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/ skip@calendar.com | Musi-Cal: http://concerts.calendar.com/ 518-372-5583
http://www.zope.org/Documentation/Reference/DTML I think the assignment example is on the above referenced DTML Scripting page as an example of what you might do if you could do it. It turns out that you cannot do assignments (=), but if you want to do what the example purports to do, a bit of spelunking in the object reference will reveal a Folder method called manage_changeProperties. <!--#call "manage_changeProperties(counter=counter+1)"--> will increment the counter property. -- Jim Washington
Luc> <!--#call expr="counter=counter+1"--> Luc> Counter: <!--#var counter-->
Luc> When I try to view the page, I get the following error: ... Luc> File /usr/local/Zope/lib/python/DocumentTemplate/VSEval.py, line 170, in __init__ Luc> (Object: counter=counter+1) Luc> File "<string>", line 1 Luc> counter=counter+1 Luc> ^ Luc> SyntaxError: invalid syntax Luc> ===================
I'm not sure what example you're referring to, or precisely what the solution is, but it looks to me like you're putting a statement (counter=counter+1) where an expression (e.g., counter+1) is required.
Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/ skip@calendar.com | Musi-Cal: http://concerts.calendar.com/ 518-372-5583
On Sat, 19 Dec 1998, Jim Washington wrote:
<!--#call "manage_changeProperties(counter=counter+1)"--> will increment the counter property.
-- Jim Washington
Luc> <!--#call expr="counter=counter+1"--> Luc> Counter: <!--#var counter-->
When I tried it long ago I did: <!--#call expr="_['counter']=_['counter']+1"--> I believe it worked but I can't remember for sure Pavlos
Hi Pavlos (Pavlos Christoforou), in <Pine.LNX.3.96.981219144251.20832C-100000@gaaros.msrc.sunysb.edu> on Dec 19 you wrote:
When I tried it long ago I did: <!--#call expr="_['counter']=_['counter']+1"--> I believe it worked but I can't remember for sure
And I cheated. Used External methods. Two reasons : 1) it was easier to figure out 2) I could apply host restrictions on the increment (I didn't want certain hosts or users to increment it.) def incr_property(self, name, value): if self.REQUEST['AUTHENTICATED_USER'] == 'me' or self.REQUEST['REMOTE_HOST'] == 'myhost' : # and some more stuff that I won't go into return value else : value = value+1; self.manage_changeProperties({name: value}) return value Then increment and display (std footer inserts it if it exists) : <!--#call "incr_property('hitcounter',hitcounter)"--> <!--#var standard_html_footer--> I keep the incr_property out of the footer because I only want certain objects to increment it, but all objects that can find that property to display it, thus display is in the footer. Kent
On Sat, 19 Dec 1998, Kent Polk wrote:
Hi Pavlos (Pavlos Christoforou), in <Pine.LNX.3.96.981219144251.20832C-100000@gaaros.msrc.sunysb.edu> on Dec 19 you wrote:
When I tried it long ago I did: <!--#call expr="_['counter']=_['counter']+1"--> I believe it worked but I can't remember for sure
And I cheated. Used External methods. Two reasons :
1) it was easier to figure out 2) I could apply host restrictions on the increment (I didn't want certain hosts or users to increment it.)
This is how I do it too (for reason (1))! In fact my Counter class creates a counter for each page and also increments a global variable, so I can see how many hits each individual page receives. Pavlos
participants (5)
-
Jim Washington -
kent@eaenki.nde.swri.edu -
lstep@mail.dotcom.fr -
Pavlos Christoforou -
skip@calendar.com