RFC: schema by interface
whit <whit-UE+B0n23d/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
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.
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.
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.
-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