Updating auto incrementing counter in a propertysheet
What am I doing wrong here ... please !! I am trying to make an autoincrementing counter for use in a diskussion forum. It's purpose is to autogenereate id's for new messages. It is important that the id's are in order, so I need to make them this way. I have a zClass (objectmanger) with a property called "lastID", on a propertysheet called "hidden". I have then written a dtml mehtod that should return the id incremented by 1 and then sets the lastID to this new id. the dtml for the "newID()" dtml method looks like this: ---------- <dtml-call "REQUEST.set('new_id', lastID+1)"> <dtml-call "REQUEST.set(lastID, new_id)"> <dtml-return "_.int(new_id)"> ---------- When I try to get the property directly via the browser i get a result of "1" The default value for lastID=0 to begin with so this sounds plausible, but when I refresh the browser nothing happens. So I guess that lastID isn't updated in the above code. How do I do that? Also when I the try to insert "newID()" in my "mxm_comment_add" method in my zClass, to autogenerate numbers, like this: <dtml-with "mxm_comment.createInObjectManager(newID(), REQUEST)"> I get the following traceback: (And I would expect it to run at least 1 time with "1" as a new id.) Traceback (innermost last): File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 222, in publish_module File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 187, in publish File C:\mxmZope\lib\python\Zope\__init__.py, line 221, in zpublisher_exception_hook (Object: RoleManager) File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 171, in publish File C:\mxmZope\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: index_html) File C:\mxmZope\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: index_html) File C:\mxmZope\lib\python\App\Factory.py, line 178, in index_html (Object: RoleManager) File C:\mxmZope\lib\python\OFS\DTMLMethod.py, line 172, in __call__ (Object: mxm_comment_add) File C:\mxmZope\lib\python\DocumentTemplate\DT_String.py, line 528, in __call__ (Object: mxm_comment_add) File C:\mxmZope\lib\python\DocumentTemplate\DT_With.py, line 133, in render (Object: mxm_comment.createInObjectManager(newID(), REQUEST)) File C:\mxmZope\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval (Object: mxm_comment.createInObjectManager(newID(), REQUEST)) (Info: newID) File <string>, line 0, in ? File C:\mxmZope\lib\python\OFS\DTMLMethod.py, line 168, in __call__ (Object: newID) File C:\mxmZope\lib\python\DocumentTemplate\DT_String.py, line 528, in __call__ (Object: newID) File C:\mxmZope\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval (Object: REQUEST.set('new_id', lastID+1)) (Info: REQUEST) File <string>, line 0, in ? NameError: (see above)
[..]
When I try to get the property directly via the browser i get a result of "1" The default value for lastID=0 to begin with so this sounds plausible, but when I refresh the browser nothing happens. So I guess that lastID isn't updated in the above code.
I think this is a class - object problem. Each time you create an object based on your ZClass, the lastID becomes 0. Each object has its own lastID, rather than what you are expecting which is one instance of last id. My advice... download and install FSCounter from Zope.org (http://www.zope.org/Members/andym/FSCounter) Add an FSCounter, call it "Unique" and turn Cookie? to OFF (very important). This will generate and keep track of an incrementing value on the file system Then in your constructor add / change: <dtml-let u=Unique> <dtml-call "REQUEST.set('unique', u)"> </dtml-let> <dtml-with "mxm_comment.createInObjectManager(_.str(REQUEST['unique']), REQUEST)"> That should work like a charm.
On Mon, 23 Oct 2000, Max Mřller Rasmussen wrote:
I have a zClass (objectmanger) with a property called "lastID", on a propertysheet called "hidden".
I have then written a dtml mehtod that should return the id incremented by 1 and then sets the lastID to this new id.
the dtml for the "newID()" dtml method looks like this: ---------- <dtml-call "REQUEST.set('new_id', lastID+1)"> <dtml-call "REQUEST.set(lastID, new_id)">
In the above line --- do you want to set up new value for ZClass property, isn't it ? If so, you have to use manage_changeProperties method of property sheet. ololo@zeus.polsl.gliwice.pl /--------------------------------------\ | `long long long' is too long for GCC | \--------------------------------------/
Max Møller Rasmussen wrote:
What am I doing wrong here ... please !!
I am trying to make an autoincrementing counter for use in a diskussion forum. It's purpose is to autogenereate id's for new messages.
It is important that the id's are in order, so I need to make them this way.
Is it more important that they be in an order, or that they be in a specific sequential list? For example, an id based upon time stamp would indeed provide IDs that re orderable (thus handling the in order part). While a list od IDs named 1,2,3,4... is more like a 'linked list', where you know what follows and what precedes a given id. However, by using objectIds, you can obtian a list of ids in a given object (folder), and thus provide one for yourself, if needed. FTR, I have implemented both ways of doing it. I am leaning towards the timestamp as being more effective, & simpler. -- E PLURIBUS LINUX
participants (4)
-
Aleksander Salwa -
Andy McKay -
Bill Anderson -
Max Møller Rasmussen