Re: RFC: schema by interface
Rob Miller <ra-UE+B0n23d/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
whit wrote: > Finally, insomnia gave me enough time to try this: > > http://svn.plone.org/svn/archetypes/Archetypes/branches/whitmo-schema-by-iface/ i've been (inadvertently) not following this list for a few months now (forgot to subscribe when i switched to a new NNTP reader), am just now getting caught up... i replied to an earlier inquiry from optilude earlier today, missed this thread altogether... sorry about that. > there is one test failure and one error(not sure if these are related). > Essentially, all calls to BaseObject.Schema now get passed to > ISchema(self). The adapter takes care of fetching the schema object > from the instance and doing the aquisition wrapping. as i mentioned in the earlier post, i'd recommend using ISchemaConsumer as a marker interface on the content and ISchemaProvider as the interface that actually provides the schema, just to make things a bit more clear. > all but 2 of the tests pass. haven't tried much else. > > The adapter acts as a proxy of sorts, delegating all calls to the > wrapped schema object (this is actually achieved by fully copy the > schemas __dict__ and __class__ over the adapter's). This is a bit of > hack, but it should give some ideas about other possibilities in this > realm. hmm.... yeah... not sure about this. > here is one simpler alternative, registering a function as the schema > factory requires less code and is probably easier to understand:: > > >>> from Acquisition import ImplicitAcquisitionWrapper as wrap > >>> def pschema_fetcher(inst): > ... return wrap(inst.schema) > > I'm curious to see if the following would work:: > > >>>from mytype import MyATSchema # some schema built at import time > >>>def module_schema_fetcher(inst): > ... return wrap(MyATSchema) > > The next obvious step is something like this:: > > >>> from archetypes.schema.interface import ILocalSchema > >>> from zope.component import getUtility > >>> def utility_schema_fetcher(inst): > ... util = getUtility(ILocalSchema, name="schema_locker") > ... schema=util.composeSchema(inst) > ... return wrap(schema) > > > Anyhoo, framework-headz have a look, give me some feedback. i'd definitely lean towards these options... it feels safer and cleaner to me to return a schema object that is wrapped only in the context object, not the view itself. -r ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642