[Zope] Updating auto incrementing counter in a propertysheet

Max Møller Rasmussen maxm@normik.dk
Mon, 23 Oct 2000 16:06:27 +0200


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 &lt;string&gt;, 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 &lt;string&gt;, line 0, in ?
NameError: (see above)