[Grok-dev] Alternative Layout System in Grok with z3c.template/z3c.pagelet
Christian Klinger
cklinger at novareto.de
Fri Mar 20 04:55:32 EDT 2009
Hi Souheil,
i ´ve added your suggestions into megrok.pagelet.
What do you think about not raising an error
if there is no layout found. Instead return only the
template not rendered in a layout. So you can use
always the Pagelet component and you don´t need grok.View.
No matter if you want the pagelet renderd in a layout
or not.
I had a disucssion with faassen about this topic. Maybe he
can jump in give us his opinion...
Thanks Christian
> I checked out the last version and here are my suggestions :
>
>
> ===== component.py =====
>
> import grok
> from zope.component import queryMultiAdapter
> from z3c.template.interfaces import ILayoutTemplate
> from zope.publisher.publish import mapply
>
>
> class Layout(object):
> """ A basic class for Layouts"""
> pass
>
>
> class Pagelet(grok.View):
> """This is the BaseClass for view Pagelets
> """
> grok.baseclass()
> layout = None
>
> def render(self):
> return self._render_template()
>
> render.base_method = True
>
> def __call__(self):
> """Calls update and returns the layout template which calls render."""
> self.update()
> if self.layout is None:
> layout = queryMultiAdapter(
> (self.context, self.request), ILayoutTemplate)
> if layout is None:
> raise NotImplementedError(
> """Impossible to find a suitable layout for %r.
> This is an unimplemented siutation. Please, provide
> a useable layout or check your components.""" % self
> )
> return layout(self)
> return self.layout()
>
>
> class FormPageletMixin(object):
> """This is the BaseClass for form Pagelets
> """
> layout = None
>
> def __call__(self):
> """Calls update and returns the layout template which calls render.
> """
> mapply(self.update, (), self.request)
> if self.request.response.getStatus() in (302, 303):
> return
>
> self.update_form()
> if self.layout is None:
> layout = queryMultiAdapter(
> (self.context, self.request), ILayoutTemplate)
> if layout is None:
> raise NotImplementedError(
> """Impossible to find a suitable layout for %r.
> This is an unimplemented siutation. Please, provide
> a useable layout or check your components.""" % self
> )
> return layout(self)
> return self.layout()
>
>
>
>
>
> 2009/3/19 Christian Klinger <cklinger at novareto.de>:
>> Hi,
>>
>>
>>> I understand the problem, now. Using the View grokker, the template
>>> validation fails because of the provided render method.
>>> Even more, the Pagelet does provide the IGrokView interface from
>>> grokcore.view, not grok, so no application_url nor flash.
>>> Though, these methods are needed in case of grok app devs. It's really
>>> too bad that there no grokcore.view.View mixin nor grok.View one, to
>>> allow the reusability of these methods and save some code duplication.
>> yes you are right in your point of view. I had a look to the
>> implementation of grokcore.viewlet it´s the same in this module. The
>> namespace, default_namespace, and __init__ are nearly the same as in
>> grok.View.
>>
>> For the megrok.pagelet.Pagelet i will implement the interface form grok
>> and not grokcore.View so we should have the application_url and flash.
>>
>> Thanks again for your feedback
>> Christian
>>
>>
>>> 2009/3/18 Souheil CHELFOUH <trollfot at gmail.com>:
>>>> As far as I can see, Pagelets are Views with a different __call__
>>>> method that looks for the layout.
>>>> I also see that you entirely recoded the grokker for that component.
>>>> Wouldn't that be smart to make a megrok.pagelet.Pagelet inherit from
>>>> grok.View as a baseclass, and simply redefine the __call__ method and
>>>> the namespace (if needed) ?
>>>> Here, using a brand new component will make it hardly maintainable, as
>>>> it already lacks 'flash' and 'application_url' from the IGrokView.
>>>>
>>>>
>>>> 2009/3/18 Jan Ulrich Hasecke <juhasecke at googlemail.com>:
>>>>> Am 18.03.2009 um 10:12 schrieb Christian Klinger:
>>>>>
>>>>>> This is a short summary what?s the current status of
>>>>>> megrok.pagelt:
>>>>> Is there any example code. I would like to play around and need a
>>>>> kick-start.
>>>>>
>>>>> juh
>>>>> _______________________________________________
>>>>> Grok-dev mailing list
>>>>> Grok-dev at zope.org
>>>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>>>>
>>>>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> http://mail.zope.org/mailman/listinfo/grok-dev
>>
More information about the Grok-dev
mailing list