plone - DocTest fails when creating an object -
i'm having problem doctest because i'm trying rename ids of content type object in iobjectaddedevent handler. requirement have ids sequential , context specific eg cam-001, cam-002, blk-001, blk-002, etc
when add object manually in browser event handler renames id correctly when try create in doctest fails after added it's container. plone.dexterity addcontenttocontainer calls _setobject original id, event handler kicks in , renames id, , when _getobject uses original id can't find object bomb attribute error.
i created product illustrate here https://github.com/mikejmets/wt.testrig.
i tried using plone.api in doctest fails.
all ideas welcome.
since using dexterity, best solution write own namegenerator
behavior.
i guess dx content has following behavior activated: <element value="plone.app.content.interfaces.inamefromtitle" />
this bahavior responsible rename item after creation. should remove , add own.
example:
register behavior zcml.
<plone:behavior title="special name(id) generator" description="" provides="dotted.name.to.your.inamegenerator" factory="dotted.name.to.your.name_generator.namegenerator" for="dotted.name.to.content.interface" />
corresponding python code.
from plone.app.content.interfaces import inamefromtitle zope.component import getutility zope.interface import implements class inamegenerator(inamefromtitle): """behavior interface. """ class namegenerator(object): """customized name title behavior." """ implements(inamegenerator) def __init__(self, context): self.context = context @property def title(self): # implementation title = ... return title
important: inherit interface inamefromtitle
now add <element value="dotted.name.to.your.inamegenerator" />
contents behaviors.
probably removing inamefromtitle
behavior content type enough, implement explicitly own behavior better.
Comments
Post a Comment