Newbie question on page counters
I'm in the process of learning Zope hacking, and I'm having a really hard time getting a page counter to work. It isn't even that page counters are all that important to me, it's that I feel that if I can't even do something this simple, what hope do I have doing something really hard? Here's what I've done. (1) Under "Properties" I've created two properties (both ints) counter_starting_value, which I've set to 11 (arbitrarily) counter_value, which I've set to 0 (2) I then created a DTML method. I spent some time pouring through the DTML Reference, but I really didn't find a lot on how to modify variables. Here's what I tried: <dtml-if counter_value> <dtml-let counter_value = counter_value + 1> </dtml-let> <dtml-else> <dtml-let counter_value = counter_starting_value> </dtml-if> <dtml-var counter_value> This didn't work. The error message reported that the syntax in the first (and probably the second, but I never got past the first) dtml-let command was wrong. I also tried things like <dtml-var "counter_value=counter_value+1"> # got a syntax value for dtml-var here <dtml-var expr="counter_value=counter_value+1"> #same problem here. Is there an easy way to do this? Thanks in advance, Rick -- Richard P. Muller, Ph.D. rpm@wag.caltech.edu http://www.wag.caltech.edu/home/rpm
"Richard P. Muller" wrote:
I'm in the process of learning Zope hacking, and I'm having a really hard time getting a page counter to work. It isn't even that page counters are all that important to me, it's that I feel that if I can't even do something this simple, what hope do I have doing something really hard?
The ZODB is a _really_ bad place to store a page counter, especially on a busy site. Data.fs will grow each time your counter increments. This is because it's a transactional daatbase with undo ability...
Here's what I've done. (1) Under "Properties" I've created two properties (both ints) counter_starting_value, which I've set to 11 (arbitrarily) counter_value, which I've set to 0
Sounds good :-)
<dtml-if counter_value> <dtml-let counter_value = counter_value + 1> </dtml-let> <dtml-else> <dtml-let counter_value = counter_starting_value> </dtml-if> <dtml-var counter_value>
This didn't work. The error message reported that the syntax in the first (and probably the second, but I never got past the first) dtml-let command was wrong.
Whoops, just remember this: DTML is not a programming language, it is designed for data presentation and form processing. Or something like that ;-) To do what you want, you probably want something like: <dtml-call "manage_changeProperties(counter_value=getProperty(counter_value,counter_starting_value-1)+1)"> Which isn't pretty :S cheers, Chris
Chris Withers wrote:
To do what you want, you probably want something like:
<dtml-call "manage_changeProperties(counter_value=getProperty(counter_value,counter_starting_value-1)+1)">
Erk, maybe this: <dtml-call "manage_changeProperties(counter_value=getProperty('counter_value',getProperty(counter_starting_value,0)-1)+1)"> Chris
Chris Withers wrote:
Chris Withers wrote:
To do what you want, you probably want something like:
<dtml-call "manage_changeProperties(counter_value=getProperty(counter_value,counter_starting_value-1)+1)">
Erk, maybe this: <dtml-call
"manage_changeProperties(counter_value=getProperty('counter_value',getProperty(counter_starting_value,0)-1)+1)">
Chris
Words simply cannot express my gratitude. Can you clue me in a bit more on the functions you called. Looks like they are manage_changeProperties(), getProperty(). I'm guessing these are both Python functions. Where are they documented, so I can learn more? You mentioned that (1) DTML is not a programming language, and that (2) ZODB is a bad place to start on Zope programming. By these two points, should I infer that learning how to write external methods in Python *is* a good place? Can you, or someone else on the list, give me a suitable homework assignment for a first Zope programming project? I was toying with the idea of writing a checkbook register in Zope, but I think it might be beyond my capacities right now. Thanks again, Rick -- Richard P. Muller, Ph.D. rpm@wag.caltech.edu http://www.wag.caltech.edu/home/rpm
"Richard P. Muller" wrote:
"manage_changeProperties(counter_value=getProperty('counter_value',getProperty(counter_starting_value,0)-1)+1)"> Words simply cannot express my gratitude.
Wow, guess it worked then... that was a bit of luck (I didn't actually test it ;-)
Can you clue me in a bit more on the functions you called. Looks like they are manage_changeProperties(), getProperty(). I'm guessing these are both Python functions. Where are they documented, so I can learn more?
They are APIs/Interfaces exposed by Zope for manipulating properties (a notoriously difficult thing to do in Zope :S) See http://www.zope.org/Members/michel/Projects/Interfaces/PropertyManager for the full list.
You mentioned that (1) DTML is not a programming language,
A half joke. DTML, IMHO, is not supposed to be a programming language but until Python and Perl methods become freely available, you have little option but to program in it. External Methods can be a real pain (do NOT try using them with Zope versions ;-)
ZODB is a bad place to start on Zope programming.
Not quite. My point was that storing highly dynamic data (such as a page counter) in a transactional database like the ZODB's normal FileStorage is a bad idea since you'll use up loads of disk space very quickly...
By these two points, should I infer that learning how to write external methods in Python *is* a good place?
Er, maybe, but that's not what I'd recommend.
Can you, or someone else on the list, give me a suitable homework assignment for a first Zope programming project? I was toying with the idea of writing a checkbook register in Zope, but I think it might be beyond my capacities right now.
My first port of call was the Zope Content Managers Guide (http://www.zope.org/Documentation/Guides/ZCMG) I worked through that to get the basics (The DTML Reference (http://www.zope.org/Documentation/Guides/DTML) can help but is _really_ out of date) Beehive (www.beehive.de) do what is allegedly quite a good guide to ZClasses, which you'll want to know at some point. You should be using Zope 2.2 as well. This has a Tutorial you can go through which may cover the stuff above better (it should certainly be a lot more up to date ;-) as well as a great 'help' button. It should also have all the decent stable API's from http://www.zope.org/Members/michel/Projects/Interfaces documented in it by now. There should also be a Zope Book on its way from O'Reilly which hopefully make the whole thing a lot easier... If I've missed something, I hope someone else will jump in and say so :-) Hope this helps, Chris
Richard, I'd recommend getting the Zope Quick Reference (ZQR) from http://zdp.zope.org (the zope documentation project). I'ts invaluable. Phil phil.harris@zope.co.uk ----- Original Message ----- From: Richard P. Muller <rpm@wag.caltech.edu> To: Chris Withers <chrisw@nipltd.com>; <zope@zope.org> Sent: Thursday, July 27, 2000 11:44 PM Subject: Re: [Zope] Newbie question on page counters
Chris Withers wrote:
Chris Withers wrote:
To do what you want, you probably want something like:
<dtml-call
"manage_changeProperties(counter_value=getProperty(counter_value,counter_sta rting_value-1)+1)">
Erk, maybe this: <dtml-call
"manage_changeProperties(counter_value=getProperty('counter_value',getProper ty(counter_starting_value,0)-1)+1)">
Chris
Words simply cannot express my gratitude. Can you clue me in a bit more on the functions you called. Looks like they are manage_changeProperties(), getProperty(). I'm guessing these are both Python functions. Where are they documented, so I can learn more?
You mentioned that (1) DTML is not a programming language, and that (2) ZODB is a bad place to start on Zope programming. By these two points, should I infer that learning how to write external methods in Python *is* a good place?
Can you, or someone else on the list, give me a suitable homework assignment for a first Zope programming project? I was toying with the idea of writing a checkbook register in Zope, but I think it might be beyond my capacities right now.
Thanks again,
Rick -- Richard P. Muller, Ph.D. rpm@wag.caltech.edu http://www.wag.caltech.edu/home/rpm
_______________________________________________ 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 (3)
-
Chris Withers -
Phil Harris -
Richard P. Muller