Re: RFC: schema by interface
whit <whit-UE+B0n23d/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
Martin Aspeli wrote: > On Thu, 13 Apr 2006 21:12:33 +0100, whit > <whit-UE+B0n23d/[email protected]> wrote: > >> Finally, insomnia gave me enough time to try this: >> >> http://svn.plone.org/svn/archetypes/Archetypes/branches/whitmo-schema-by-iface/ >> >> >> 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. > > Yay :) > > Do you want to spell out the main benefits of doing this, for the record? > <deep breath> this is the first step in being able to return schemas via registration in the component architecture. since the component architecture supports overriding this means you could reuse content without subclassing just to get schema changes. yadda yadda. I've written enough about this subject in numerous previous emails. if anyone has questions, I'm usually on irc. >> here is one simpler alternative, registering a function as the schema >> factory requires less code and is probably easier to understand:: > > Erm... I don't quite understand it :) This may look a little different than you are used to. The functions are example "factories" for a schema retrieving adapter. They differ from most common example of adapter because they are functions rather than classes. The CA doesn't care; it's up to you to enforce that what is returned fits the interface(or doesn't if you so desire). > What's the point of doing this? >> >>> 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) > > Sorry, it's late, but can you explain what you're doing here? > The first example is a simplification of the code in Schema/adapters.py. The second is a schema from a module level variable. The third is a sketch for how schema provision via utility might work. -w ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642