[Zope] Unique ID generation

Aleksander Salwa ololo@zeus.polsl.gliwice.pl
Fri, 26 Jan 2001 06:06:25 +0100 (CET)


On Thu, 25 Jan 2001, Timothy Wilson wrote:

> Try adding the following to your ZClass add method:
> 
> <dtml-call "REQUEST.set('ts', ZopeTime())">
> <dtml-call "REQUEST.set('id', _.str(_.int(ts)))">
> 
> This will use the ZopeTime() as the id of your instance. I doubt you can add
> them faster enough to get the same one twice. :-)

When you add instances programatically, than you can add 2 in 1 second
without doubt. I use this python code:

def genId(client, namespace, prefix=''):
	no=int(client.ZopeTime())
	while namespace.hasattr(client, prefix+str(no)):
		no=no+1
	return prefix+str(no)

ololo@zeus.polsl.gliwice.pl, oleks@helper.pl

/--------------------------------------\
| `long long long' is too long for GCC |
\--------------------------------------/