I am hopelessly trying to add a eventlistner for a behavior.
I have folders content types with 'dates' behavior, defined like
<plone:behavior
title="Dates behavior"
description="Add multiple dates"
provides=".behaviors.IDatesBehavior"
for="plone.dexterity.interfaces.IDexterityContent"
/>
class IDatesBehavior(Interface):
"""List of Datetime fields"""
dates = schema.List(
title=_(u'Additional Dates'),
value_type=schema.Datetime(),
required=False,
)
alsoProvides(IDatesBehavior, IFormFieldProvider)
The plan is that these dates shall be saved inside the Folder(ish content type) on save / edit, so I added:
<subscriber
for=".behaviors.behaviors.IDatesBehavior
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".behaviors.make_dates"
/>
<subscriber
for=".behaviors.behaviors.IDatesBehavior
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".behaviors.make_dates"
/>
This works for the content with Datesbehavior but it seems like it also gets called when manually adding a Date (content type) to the folders object.
To try to work around this I added a check to see if that helped).
But no matter how I try to add or delete object, I keep getting the following errors:
RuntimeError: maximum recursion depth exceeded while calling a Python object
INFO ExtendedPathIndex Attempt to unindex nonexistent object with id -1803674900
Zope.ZCatalog uncatalogObject unsuccessfully attempted to uncatalog an object with a uid of /Plone/News/my-item/date-10
After some googling it seems like plone.api is not the right way, what could I try to add/delete objects ?
alsoProvides(IDatesBehavior, IFormFieldProvider)
def make_dates(self, context):
"""Make date content items"""
if self.portal_type == 'movie':
event_time = self.end - self.start
title = self.Title
#old_dates = self.listFolderContents(contentFilter={"portal_type" : "date"})
ids = self.keys()
if len(ids) > 0:
# manage_delObject will mutate the list
# so we cannot give it tuple returned by objectIds()
ids = list(ids)
self.manage_delObjects(ids)
#if len(old_dates) > 0:
# for old_date in old_dates:
# #plone api gives maximum rec error
# import pdb;pdb.set_trace()
# self.manage_delObjects(old_date)
# #api.content.delete(old_date)
if self.dates:
for new_date in self.dates:
import pdb;pdb.set_trace()
item = createContentInContainer(self, "date", title=title, start=new_date, end=new_date+event_time)
#self.invokeFactory("date", "date")
#api.content.create(container=self, type="date", title='title1')