[Zope] Lets try this again - auto-creation

Jim Washington jwashin@vt.edu
Sat, 17 Jul 1999 19:49:54 -0400


I did something similar for a real-time chat application.  I also added
a random number  to the count; this way, even if the counter somehow is
the same for really close-in-time posts, it is very unlikely that a
duplicate ID problem would crop up.

I also started the counter at 10000; that way alphabetical order in the
folder display keeps the IDs in the order in which they were generated,
instead of 1,10,11,12,...,2,20,...

My postmessage DTMLMethod:

<!--#call incrementcounter-->
<!--#if "_.len(message) > 0"-->
<!--#with responses-->
<!--#call
"REQUEST.set('newdocument',_.str(counter)+_.str(_.whrandom.random()))"-->
<!--#call "manage_addDTMLMethod(id = newdocument, title=username,
file=message)"-->
<!--#/with-->
<!--#/if-->
<!--#var chatform-->

Note that this is probably misuse of a DTMLMethod object; I probably
should have written a ChatPost object, but DTMLMethod had the right
number of places to put info for my purposes.

I tried to use ZopeTime earlier, but I could not get it to produce valid
object IDs;  Zope complained about invalid characters.

-- Jim Washington

Alexander Staubo wrote:
> 
> You can store a "last ID" counter as an int property on the top-level
> folder, and increment that for every object you create.
> 
> Under Zope2 the counter must be thread-safe, which means you've got to
> borrow of Zope's global -- I think -- thread locks.
> 
> --
> Alexander Staubo             http://www.mop.no/~alex/
> "He could open a tin of sardines with his teeth, strike a Swan Vestas
> on his chin, rope steers, drive a steam locomotive and hum all the
> works of Gilbert and Sullivan without becoming confused or breaking
> down in tears."
> --Robert Rankin, _The Book of Ultimate Truths_
> 
> >-----Original Message-----
> >From: zope-admin@zope.org [mailto:zope-admin@zope.org]On
> >Behalf Of Bruce
> >C. Dillahunty
> >Sent: 17. juli 1999 22:30
> >To: zope@zope.org
> >Subject: [Zope] Lets try this again - auto-creation
> >
> >
> >OK, since the last round seemed to be roundly ignored :-)
> >
> >Does anybody know of a way to create a ZClass object without
> >entering an
> >"ID"... I want the user to create an object, and the ID be
> >"autocreated" (a
> >random number, the date/time, whatever). I'll be accessing
> >them through a
> >ZCatalog searching on properties, creation date, etc. and
> >don't care about the
> >unique ID.
> >
> >Any suggestions?