five.grok and page templates

View: New views
8 Messages — Rating Filter:   Alert me  

five.grok and page templates

by Martin Aspeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

With a lot of help from Philipp, I made five.grok use
Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today. This
is necessary to make it work with Plone, and I presume other code that
makes "Zope 2" assumptions as well, e.g. the user of 'here' or reliance
on Five's provider: expression support.

We made this work by overriding the ITemplateFileFactory for the '.pt'
extension from grokcore.view and implementing a ZopeTwoPageTemplate that
extends PageTemplate and uses a ViewPageTemplateFile in
setFromFilename(). We also overrode render() to do some aq wrapping and
call the template in a different way.

Unfortunately, I haven't been able to make setFromString() work. I think
this will require a view-aware version of
Products.PageTemplates.ZopePageTemplate.ZopePageTemplate ala
ViewPageTemplateFile from Five.browser. Currently, it raises
NotImplemented. This isn't so much a problem for the filesystem .pt
scanner, but it means that inline Zope 2 style templates won't work.

Also, five.grok's __init__.py does from grokcore.view import *. Thus,
five.grok.PageTemplate is the Zope 3 one from grokcore.view, not the
ZopeTwoPageTemplate from five.grok.components. I think this could easily
get confusing. In fact, many of the ftests in five.grok use the former,
which means that they're not really testing a Zope 2 world (even if it
is legitimate to use the Zope 3 template engine in Zope 3 these days).

Should we make five.grok.PageTemplate be a Zope 2 style page template?
Should we bother to hack up a view-aware ZopePageTemplate for use with
inline templates?

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by Martin Aspeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Martin Aspeli wrote:

> Should we make five.grok.PageTemplate be a Zope 2 style page template?
> Should we bother to hack up a view-aware ZopePageTemplate for use with
> inline templates?

Actually, this was easier than I thought. I added a
ViewAwareZopePageTemplate to five.grok.components that replicates the
pt_getEngine() and pt_getContext() overrides from Five's
ZopeTwoViewPageTemplate.

I then added this to five.grok's __init__.py:

   # Override the one from grokcore.view so that we get Zope 2 semantics
   from five.grok.components import ZopeTwoPageTemplate as PageTemplate

The tests, including the old ftests, still pass, and I've added a test
to show inline templates working with Zope 2 semantics.

Please review and tell me if this all makes sense! Is there a use case
for sticking with zope.pagetemplate type semantics here?

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by wichert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Previously Martin Aspeli wrote:

> Hi,
>
> With a lot of help from Philipp, I made five.grok use
> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today. This
> is necessary to make it work with Plone, and I presume other code that
> makes "Zope 2" assumptions as well, e.g. the user of 'here' or reliance
> on Five's provider: expression support.
>
> We made this work by overriding the ITemplateFileFactory for the '.pt'
> extension from grokcore.view and implementing a ZopeTwoPageTemplate
> that extends PageTemplate and uses a ViewPageTemplateFile in
> setFromFilename(). We also overrode render() to do some aq wrapping and
> call the template in a different way.

Have you checked if this still works with z3c.jbot? That should be a
requirement before using something like this in Plone.

Wichert.

--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.
_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by Philipp von Weitershausen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wichert Akkerman wrote:

> Previously Martin Aspeli wrote:
>> Hi,
>>
>> With a lot of help from Philipp, I made five.grok use
>> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today. This
>> is necessary to make it work with Plone, and I presume other code that
>> makes "Zope 2" assumptions as well, e.g. the user of 'here' or reliance
>> on Five's provider: expression support.
>>
>> We made this work by overriding the ITemplateFileFactory for the '.pt'
>> extension from grokcore.view and implementing a ZopeTwoPageTemplate
>> that extends PageTemplate and uses a ViewPageTemplateFile in
>> setFromFilename(). We also overrode render() to do some aq wrapping and
>> call the template in a different way.
>
> Have you checked if this still works with z3c.jbot? That should be a
> requirement before using something like this in Plone.

z3c.jbot does heavy monkey patches to Zope itself. I'm not in the
business of tell you guys what to do, but I personally refuse to adjust
my code to be defensive against wild monkey patches like that. And I
think it'd be sad if a new requirement for Plone-related code was now
not to dare break something as fragile as that.

I'm also not sure what you're implying here. That five.grok-based views
should be customizable through z3c.jbot? I consider this a questionable
goal. With Grok-like configuration, views have become a cheap commodity
to produce. Which means it should also be much easier now to rely on the
Component Architecture for overriding existing functionality (something
z3c.jbot should've done in the first place).
_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by Martin Aspeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wichert Akkerman wrote:

> Previously Martin Aspeli wrote:
>> Hi,
>>
>> With a lot of help from Philipp, I made five.grok use
>> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today. This
>> is necessary to make it work with Plone, and I presume other code that
>> makes "Zope 2" assumptions as well, e.g. the user of 'here' or reliance
>> on Five's provider: expression support.
>>
>> We made this work by overriding the ITemplateFileFactory for the '.pt'
>> extension from grokcore.view and implementing a ZopeTwoPageTemplate
>> that extends PageTemplate and uses a ViewPageTemplateFile in
>> setFromFilename(). We also overrode render() to do some aq wrapping and
>> call the template in a different way.
>
> Have you checked if this still works with z3c.jbot? That should be a
> requirement before using something like this in Plone.

I haven't.

I would definitely like it to work with z3c.jbot. However, z3c.jbot is
neither a part of Plone core, nor Zope core, nor anything else, is
fairly new, and does some deep monkey patching. I'm not comfortable
recommending it as a long-term solution to people who are new to Plone
yet, and I'm not comfortable committing Zope/Five/Plone to having to
support it indefinitely.

This discussion belongs elsewhere, but if we want z3c.jbot to be such an
official part of Plone that people take it into consideration when
working on Plone (or Five!) code, then we need to submit it to the usual
process of review and discussion and include it as a maintained, core
package. We can't test with every third party solution out there. This
isn't about quality or even ubiquity: It's about the processes we have
established to help de-risk new approaches for those who do not
regularly read lists like this and establish a stable, supported
platform that doesn't grow willy-nilly.

I personally like the z3c.jbot philosophy very much. Overriding
templates should be that easy. However, I'm not convinced that it is a
strategically sensible implementation, and there has been no real review
to prove me wrong, much as I'd love to be. In fact, I think
grokcore.view holds more promise as a base for making customisation
"that easy" in a less monkey patched way.

I will endeavour to test, though, and make adjustments to make z3c.jbot
work if required and reasonable. I'm also interested in making z3c.jbot
less hacky by proposing more robust changes to Zope (or Plone).

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by wichert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Philipp von Weitershausen wrote:

> Wichert Akkerman wrote:
>> Previously Martin Aspeli wrote:
>>> Hi,
>>>
>>> With a lot of help from Philipp, I made five.grok use
>>> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today.
>>> This is necessary to make it work with Plone, and I presume other
>>> code that makes "Zope 2" assumptions as well, e.g. the user of 'here'
>>> or reliance on Five's provider: expression support.
>>>
>>> We made this work by overriding the ITemplateFileFactory for the
>>> '.pt' extension from grokcore.view and implementing a
>>> ZopeTwoPageTemplate that extends PageTemplate and uses a
>>> ViewPageTemplateFile in setFromFilename(). We also overrode render()
>>> to do some aq wrapping and call the template in a different way.
>>
>> Have you checked if this still works with z3c.jbot? That should be a
>> requirement before using something like this in Plone.
>
> z3c.jbot does heavy monkey patches to Zope itself. I'm not in the
> business of tell you guys what to do, but I personally refuse to adjust
> my code to be defensive against wild monkey patches like that. And I
> think it'd be sad if a new requirement for Plone-related code was now
> not to dare break something as fragile as that.

That's a perfectly understandable goal. I do not think z3c.jbot is useful
for grok, which I see as aimed for pure z3 applications and not large
reusable applications such as Plone.

For Plone it is essential that we have a simple way for people to customize
templates. A way that does not require designers to learn zcml, the
component architecture or any other technology that designers do not already
know. z3c.jbot is a too which provides that. I see five.grok as being at
least partially aimed at being used inside Plone, so I think this should at
the very least be investigated.

> I'm also not sure what you're implying here. That five.grok-based views
> should be customizable through z3c.jbot? I consider this a questionable
> goal. With Grok-like configuration, views have become a cheap commodity
> to produce. Which means it should also be much easier now to rely on the
> Component Architecture for overriding existing functionality (something
> z3c.jbot should've done in the first place).

It could not since it had to deal with existing Zope versions, which do not
provide any hooks that z3c.jbot can use. If you introduce new hooks now they
will not usable by Plone for one or two years and we need something in the
meantime.

Wichert.


--
Wichert Akkerman <wichert@...>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by Martin Aspeli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Wichert Akkerman wrote:

> Have you checked if this still works with z3c.jbot? That should be a
> requirement before using something like this in Plone.

I can happily report that z3c.jbot does work. :)

For example, I have example.dexterity.page, which contains:

   from five import grok
   from plone.dexterity import api as dexterity

   class IPage(dexterity.Schema):
       dexterity.model("page.xml")

   class View(grok.View):
       grok.context(IPage)
       grok.require('zope2.View')

This will result in a View for IPage called @@view. The template is
found in src/example.dexterity/example/dexterity/page_templates/view.pt.

I then did an override using z3c.jbot called
example.dexterity.page_templates.view.pt in a directory registered with
z3c.jbot, which is correctly picked up.


Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev

Re: five.grok and page templates

by Lennart Regebro-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Aug 4, 2008 at 01:58, Martin Aspeli <optilude@...> wrote:
> With a lot of help from Philipp, I made five.grok use
> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile today. This is
> necessary to make it work with Plone, and I presume other code that makes
> "Zope 2" assumptions as well, e.g. the user of 'here' or reliance on Five's
> provider: expression support.

See, I *knew* that would be necessary sooner or later, but none of the
tests failed. :-)
Good stuff.

> Should we make five.grok.PageTemplate be a Zope 2 style page template?

Yes.

> Should we bother to hack up a view-aware ZopePageTemplate for use with
> inline templates?

I think so.

--
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64
_______________________________________________
Grok-dev mailing list
Grok-dev@...
http://mail.zope.org/mailman/listinfo/grok-dev