I want to rename the id or the 'short name' as soon as an object is either
added or modified. I have managed to achieve this via the code below:
@grok.subscribe(IPerson, IObjectModifiedEvent)
def rename(person, event):
parent = person.aq_parent
parent.manage_renameObject(person.getId(), str(person.title))
However, the code only works for when an object is modified not when an
object is created. When an object is created it throws the following error:
The id "test test" is invalid - it is already in use.
I have checked and there is no id "test test" that is in use.
Here is the more consice error:
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module plone.z3cform.layout, line 64, in __call__
Module plone.z3cform.layout, line 54, in update
Module plone.z3cform.fieldsets.extensible, line 59, in update
Module plone.z3cform.patch, line 30, in GroupForm_update
Module z3c.form.group, line 138, in update
Module z3c.form.action, line 99, in execute
Module z3c.form.button, line 311, in __call__
Module z3c.form.button, line 170, in __call__
Module plone.dexterity.browser.add, line 93, in handleAdd
Module z3c.form.form, line 247, in createAndAdd
Module plone.dexterity.browser.add, line 72, in add
Module plone.dexterity.utils, line 145, in addContentToContainer
Module Products.BTreeFolder2.BTreeFolder2, line 450, in _setObject
Module zope.event, line 23, in notify
Module zope.component.event, line 26, in dispatch
Module zope.component._api, line 138, in subscribers
Module zope.component.registry, line 323, in subscribers
Module zope.interface.adapter, line 575, in subscribers
Module zope.component.event, line 33, in objectEventNotify
Module zope.component._api, line 138, in subscribers
Module zope.component.registry, line 323, in subscribers
Module zope.interface.adapter, line 575, in subscribers
Module bthft.eprs.person, line 29, in createCategories
Module plone.dexterity.utils, line 150, in createContentInContainer
Module plone.dexterity.utils, line 145, in addContentToContainer
Module Products.BTreeFolder2.BTreeFolder2, line 451, in _setObject
Module zope.container.contained, line 329, in notifyContainerModified
Module zope.event, line 23, in notify
Module zope.component.event, line 26, in dispatch
Module zope.component._api, line 138, in subscribers
Module zope.component.registry, line 323, in subscribers
Module zope.interface.adapter, line 575, in subscribers
Module zope.component.event, line 33, in objectEventNotify
Module zope.component._api, line 138, in subscribers
Module zope.component.registry, line 323, in subscribers
Module zope.interface.adapter, line 575, in subscribers
Module bthft.eprs.person, line 38, in rename
Module plone.folder.ordered, line 187, in manage_renameObject
Module OFS.CopySupport, line 350, in manage_renameObject
CopyError:
<HTML>
<HEAD>
<TITLE>Invalid Id</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<FORM ACTION="manage_main" METHOD="GET" >
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="10">
<TR>
<TD VALIGN="TOP">
<BR>
<CENTER>!</CENTER>
</TD>
<TD VALIGN="TOP">
<BR><BR>
<CENTER>
The id "test test" is invalid - it is already in use.
</CENTER>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">
</TD>
<TD VALIGN="TOP">
<CENTER>
<INPUT TYPE="SUBMIT" VALUE=" Ok ">
</CENTER>
</TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>
--
View this message in context:
http://plone.293351.n2.nabble.com/Rename-an-object-after-it-has-been-added-tp6625176p6625176.html
Sent from the Product Developers mailing list archive at Nabble.com.
_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers