[Product-Developers] at schemaextender not working right with portal factory
Jens W. Klein
jens at bluedynamics.com
Fri Sep 14 16:39:23 UTC 2012
Instead of checking the parent theres a better way to achieve goal by
using drive-by-browserlayers.
Iow apply a browserlayer at traversal time and bind the schemaextender
to the layer:
from zope.interface import alsoProvides
from .interfaces import IMyDriveByLayer
from .interfaces import IMyMarkerInterface
def apply_layer(obj, event):
if not IMyMarkerInterface.providedBy(obj) \
or IMyDriveByLayer.providedBy(event.request):
return
alsoProvides(event.request, IMyDriveByLayer)
and in zcml:
<subscriber
for="*
zope.traversing.interfaces.IBeforeTraverseEvent"
handler=".subscriber.apply_layer" />
Then all you need is a IBrowserLayerAwareExtender
Jens
On 2012-09-14 13:17, Petri Savolainen wrote:> On 12 September 2012
19:55, ajung <lists at zopyx.com
> <mailto:lists at zopyx.com>> wrote:
>
> at.schemaextender is known to work without issues with or
> without portal_factory.
>
>
> Well I guess I might come up with the exception proving the rule then ;/
> Thanks for confirming there are no known issues.
>
> Let me rephrase, just to avoid any unintended ambiguity: I am trying to
> extend content per-instance: the marker interface is assigned to the
> instance run-time, right after the instance is created. So this is not
> about the usual (?) way, ie. type-wide extension configured statically,
> which I've found to work perfectly, as well.
>
> Here's what I did to recreate the issue (ie. initial AT edit form not
> including schema extension when portal factory is used):
>
> Using a clean plone 4.2.1 buildout (latest OSX w/python 2.7), empty
> egg-cache and a simple zope/plone package with paster, I dropped this
> simplified 'extension.py' python module
> <http://pastebin.com/L95m1h58> and configure.zcml
> <http://pastebin.com/xvFtFby5> inside the pkg to hook things up so that
> any ATEvents created will be schema-extended as soon as they are created.
>
> Which again works fine, except that with portal factory, the initial
> edit form does not include the added field ("Cost"). Subsequent edit
> forms again do, as they should.
>
> I'd appreciate if someone could take a look & try it out.
>
> Thanks,
>
> Petri
>
>
>
> Petri Savolainen wrote
> >
> > Hello,
> >
> > I have an add-on whereby ATEvents are atschema-extended only if
> they are
> > created inside a folder with a particular interface. This is
done by
> > listening for the ATEvent creation event and then checking the
> parent in
> > the event handler.
> >
> > This works fine when portal factory is not used, but with it, the
> initial
> > AT creation/edit form gets rendered using the original schema,
> not the
> > extended one. Upon subsequent edits of the new instance, the
> schema is
> > there and everything works as it should.
> >
> > Any advice would be appreciated. I took a look at the FactoryTool,
> > BaseObject and Schema sources already, but got pretty much
> nowhere, nor
> > did
> > Google find anything about this.
> >
> > Thanks,
> >--
Klein & Partner KG, member of BlueDynamics Alliance
More information about the Product-Developers
mailing list