[Zope] NEWBIE: assign next free ID automatically
Kapil Thangavelu
kthangavelu@earthlink.net
Sun, 15 Oct 2000 18:46:03 -0700
ola,
the below will should work fine, although the _string.atoi is unesc
since you can just use 0, or 1 by itself inside "" and have it treated
as an int and its a bit inefficient to use objectValues over objectIds
(list of objects vs. list of strings) although it saves you from having
to do a dtml-let doc_id=sequence-item to evaluate in pythonish "" dtml
although the code below makes it obvious it should also be stated that
ids are strings.
one caveat, i wouldn't count on the id naming sequence to nesc reflect
the order of the items, as an item maybe deleted etc and have new ones
created which replace them. if you've not going to be deleting items,
another possibility is
<dtml-call "REQUEST.set(id, _.str(_.len(objectIds(['DTML
Document'])+1))">
another caveat, in a heavily hit site you're going to be generating id
errors(both methods) because one thread will commit a new doc while the
other tries a moment later to commit with the same id. hence the reason
why i would just use a random int like <dtml-call "REQUEST.set(id,
_.str(_.whrandom.randint(0,1000000))">
kapil
jensebaer wrote:
>
> Hi,
>
> it is not tested but may it works
>
> <dtml-call "REQUEST.set('newid', _.string.atoi('0'))"
> <dtml-in "objectValues('DTML Document')">
> <dtml-if "_.int(id) >= newid">
> <dtml-call "REQUEST.set('newid', _.int(id) + _.string.atoi('1'))">
> </dtml-if>
> </dtml-in>
>
> Your new id is: <dtml-var newid>
>
> may you have to use _.string.atoi(id) instead _.int(id)
>
> Viel Glück
>
> Jens
>
> ----- Original Message -----
> From: "Patrick Koetter" <p@state-of-mind.de>
> To: <zope@zope.org>
> Sent: Monday, October 16, 2000 2:59 AM
> Subject: [Zope] NEWBIE: assign next free ID automatically
>
> > Hi,
> >
> > I've been through the Guides, How-Tos and also some of the list-archives.
> > Though I am not a programmer I finally decided to ask that question to all
> > of you...
> >
> > I want to give Users the possibility to add documents in a folder
> > <things_to_do> ;-).
> > so far so good ... Then I want to control the IDs simply by assigning an
> ID
> > to their Form.
> > I found a few articles generating either randomIDs or calculating IDs from
> > ZopeTime().
> >
> > What is it that I want to do?
> > I want to evaluate the highest ID (all are 'int') within the folder and
> > assign the next highest.
> > I'm sure this is easy to you...
> >
> > If there's a RTFM-document I'd be glad to read that.
> >
> > thanks,
> >
> > p@rick
> >
> >
> > _______________________________________________
> > Zope maillist - Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > ** No cross posts or HTML encoding! **
> > (Related lists -
> > http://lists.zope.org/mailman/listinfo/zope-announce
> > http://lists.zope.org/mailman/listinfo/zope-dev )
> >
> >
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )