[Zope] Re: Thanks for the Zope Help Yesterday

Casey Duncan cduncan@kaivo.com
Wed, 14 Mar 2001 08:13:15 -0700


David Kyte wrote:
> 
> Do you know of any simple way of generating sequential
> numbers eg Order numbers in a persistant global way?
> 
> Thanks
> 
> Dave.
> 
> PS
> 
> Hard stuff is easy with zope, but some easy stuff can be
> really hard. In perl I would just lock a file, bump the
> value, and then return the value.

Used to be you could create a ZClass for your order and store a class
attribute that could be "bumped" up everytime you create an instance of
the class. However I found a security flaw in this, and DC eradicated it
in a recent hotfix. You can however still do it from an external method
AFAIK. Create an external method like so:

def getNextNumber(ZClass):
	if hasattr(ZClass, 'sequence'):
		ZClass.setClassAttr('sequence', ZClass.getClassAttr('sequence') + 1)
	else:
		ZClass.setClassAttr('sequence', 1)
	
	return ZClass.getClassAttr('sequence')

Then call it from the ZClass constructor method (which is usually a DTML
method, but could be a Python script) and use the value it returns to
either set the id or whatever property you are storing the order number
into.

I would like to see a secure version of this functionality exposed to
DTML and TTW scripts, but DC seems a bit adverse to the idea. I will
probably create a patch at some point anyhow and see if they like it.
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>