[Zope] Unique ID generation

Timothy Wilson wilson@visi.com
Thu, 25 Jan 2001 17:40:45 -0600 (CST)


On 25 Jan 2001, Tim Moore wrote:

> I'm writing a simple ZClass (and a second ZClass which contains the
> first) and I would like the constructor for this class to be able to
> auto-generate unique IDs for the instances rather than making the
> owner choose one.

Some people call me "Tim" too. :-)

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. :-)

-Tim

--
Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |                              | http://slashdot.org/
wilson@visi.com |   <dtml-var pithy_quote>     | http://linux.com/