[Grok-dev] Time for a global_adapter?
Martin Aspeli
optilude+lists at gmail.com
Sat Apr 4 05:07:13 EDT 2009
Hi,
If I'm not missing something, it's not possible to do this without ZCML:
from z3c.form.widget import ComputedWidgetAttribute(
def getDefault(data):
return "blah"
DefaultValueProvider = ComputedWidgetAttribute(
getDefault, field=IMySchema['some_field'])
<adapter factory=".DefaultValueProvider" name="default" />
That is - I'm using a factory (ComputedWidgetAttribute in this case) to
obtain an adapter, which I then need to register under a name.
I could imagine something like:
grok.global_adapter(DefaultValueProvider, name="default")
to mimic grok.global_utility().
Do we need something like this?
As I've said before, I also think we should support named @adapter
decorators, e.g.
@adapter(IFoo, name="foo")
def foo(context):
...
although that's slightly different.
Martin
--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
More information about the Grok-dev
mailing list