[Grok-dev] Re: Does it make sense: registering factories that
are functions not classes
darryl at darrylcousins.net.nz
Tue Jun 5 16:00:58 EDT 2007
On Tue, 2007-06-05 at 17:44 +0200, Jan-Wijbrand Kolman wrote:
> > I checked out the branch and tried the decorators. It seems then you can
> > only use a method for the adaptor. Is this expected or is there a way to
> > use classes that I'm missing? For example to get ISized I needed to use
> > the method to return a class:
> > @grok.adapter(JanW)
> > @grok.implementer(ISized)
> > def sizedForJanW(context):
> > return ActualSizedAdapterForJanW(context)
> > Which gets me an adapter class *and* a decorated method. Surely just as
> > easy to use an adapter sub-classing grok.Adapter. From memory all my
> > adapters to date need to be classes.
> > I'm sure I'm missing something and am keen to be enlightened.
> It is complementary to grok.Adapter.
Ahh. Now I understand.
The couple of simple cases that I made to try out the decorators worked
I'm not really qualified to review your code but ...
+1 to merge.
Thanks for the info.
> Sometimes its very useful to have a simple function that acts as an
> adapter factory. That is what this decorator notation is for. One
> real-world example for which this could be useful is:
> vocabulary = SimpleVocabulary.fromValues(('a', 'b', 'c', 'd', 'e'))
> @grok.adapter(ISet, IBrowserRequest)
> def selection_widget(field, request):
> return MultiCheckBoxWidget(field, field.value_type.vocabulary, request)
> class Index(grok.Form):
> form_fields = grok.Fields(
> def handle_submit(self, **data):
> But see also the start post for this thread.
> kind regards,
More information about the Grok-dev