Open erral opened 5 years ago
It looks like the field is called 'effective' https://github.com/plone/plone.app.dexterity/blob/master/plone/app/dexterity/behaviors/metadata.py#L1491 and 'effective_date' is just a getter of that value and not a setter: https://github.com/plone/plone.app.dexterity/blob/master/plone/app/dexterity/behaviors/metadata.py#L3972
In Plone 4, we had a similar problem, but for expiration date.
from Products.CMFPlone.PloneTool import CEILING_DATE
# obj is from a brain.getObject()
obj.expires = CEILING_DATE
obj.expiration_date = None
obj.reindexObject()
Don't know if all the lines from the snippet above were needed, but we had to call obj.reindexObject()
entirely (instead of just obj.reindexObject(idxs=['modified'])
for example) or the item wasn't available from portal_catalog
for anonymous users.
Reported at the community forum:
https://community.plone.org/t/seteffectivedate-in-plone4-vs-plone5/8515
BUG/PROBLEM REPORT (OR OTHER COMMON ISSUE)
What I did:
We want to reset the Effective Date of some Dexterity Types, which are derived from NewsItems, as we often use the Effective Date as sort criterum. We used to have python scipts for that, which worked fine in our PLONE 4 Instanzes but don't work in our PLONE 5 sites. In one case it looks like this and should set the Eff.Date to the Creation Date:
dateorg=context.ZopeTime() dateString = dateorg.strftime('%Y/%m/%d %T') date = context.CreationDate() oldeff = context.EffectiveDate() context.setEffectiveDate(date) neweff = context.EffectiveDate() context.reindexObject() return "Date now %s. Creat = %s . New Eff = %s . Old Eff = %s ." % (dateString,date,neweff,oldeff )
The output of the script shows the old and the new Eff.Date as expected, but when I edit the context object in PLONE it still shows the old Eff.Date. That means, even if context.EffectiveDate() gives the new Date after having it changed, it does not store that in the object itself.
Any hints, were that problem is? Did I miss something?
What I expect to happen:
Under PLONE 4 it works as expected.
What actually happened:
PLONE 5 Docus tell me that setEffectiveDate(date) still should work as before.