开发者

Automatically create new objects in a Plone Folder, being the ids only sequential numbers

开发者 https://www.devze.com 2023-03-14 06:06 出处:网络
I have the following structure: /Plone/folder/year/month/day/id I want to create the last id sequentially in a tool开发者_如何转开发 using invokeFactory. I want to have:

I have the following structure:

/Plone/folder/year/month/day/id

I want to create the last id sequentially in a tool开发者_如何转开发 using invokeFactory. I want to have:

/Plone/folder/2011/06/21/1
/Plone/folder/2011/06/21/2
/Plone/folder/2011/06/21/3
/Plone/folder/2011/06/21/4

Instead of:

/Plone/folder/2011/06/21/id-1
/Plone/folder/2011/06/21/id-2
/Plone/folder/2011/06/21/id-3
/Plone/folder/2011/06/21/id-4

...that is automatically done when I try to create an object with the same name in a folder, Plone handles that for me adding a sequential number. I want an efficient way to create objects, but only using a sequential number instead of a name with a sequential number. I can do that getting the total number os items in a folder, but would like to know if there's a better way.

Real life example: http://plone.org/products/collective.captcha/issues/4


If you're creating these objects manually, you can do something like:

brains = context.getFolderContents({'sort_on' : 'id', 'sort_order' : "reverse"})
if len(brains) > 0:
  id = str(int(brains[0].id) + 1)
else:
  id = '1'

Then you'll have to create the object manually with that id.

If you want this to do done automatically for you when a user creates content, you might want to look into creating a content rule to change the id of the content for you. An example that might help is collective.contentrules.yearmonth

0

精彩评论

暂无评论...
验证码 换一张
取 消