RE: [Zope] NEWBIE: assign next free ID automatically
This is untested, but an idea: dtml-in "objectValues()[:-1]" sort=id reverse dtml-call "REQUEST.set('new_id', id+1)" dtml-var new_id It is still subject to failure if 2 or more processes are writing an article in the same time. Furthermore it has to find and sort all the items in the folder. That could take a long time if there are lots of them. Maybe you should somehow insert a dtml-try until you succed in writing the article. Another aproach would be to have the folder with your articles have a property "lastID" and let "nexID" be a method that automatically would increment lastID end return it. Maybe it is possible to lock the lastID property?? From: Patrick Koetter [mailto:[EMAIL PROTECTED]] 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... ___ Zope maillist - [EMAIL PROTECTED] 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 )
Re: [Zope] NEWBIE: assign next free ID automatically
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,100))" 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" [EMAIL PROTECTED] To: [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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] 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 - [EMAIL PROTECTED] 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 )
Re: [Zope] NEWBIE: assign next free ID automatically
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" [EMAIL PROTECTED] To: [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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 - [EMAIL PROTECTED] 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 )