Martijn Faassen wrote:
Chris Withers <[EMAIL PROTECTED]> wrote:
Martijn Faassen wrote:
        class TemplateView(grok.View):
            template = unassociated
            module_info = module_info_

I'm not sure. Debugging becomes a nightmare with generated classes, which is how I ran into these problems in the first place.

Can you explain what the what the above code snippet actually does?

It generates a view for a template file that doesn't have its own view.

Okay, but isn't this just a currying problem?

If so, there's all the usual python currying solutions, here's one...

class ViewFactory:

   implements(IView)

   def __init__(self,klass):
       self.template = PageTemplateFile(klass.template_name)
       self.klass = klass

   def __call__(self,context,request):
       return self.klass(template,context,request)

class MyView:

   template_name = ''

provideAdapter(ViewFactory(MyView),(IContext,IRequest),IView)

Possibly. It's not that bad right now. The difficulty is that I do
need to generate a class, not an instance, as I can only initialize the
instance when the view is initialized because the context and request
are needed.

There's something to be said for circumstances where creating an adapter each time it's asked for is sub-optimal, but I don't have a good enough feel for the problem in its generic sense to make any suggestions...

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
           - http://www.simplistix.co.uk

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to