Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: CMF

DirectoryViewSurrogate as context in FSPageTemplates

 

 

Zope cmf RSS feed   Index | Next | Previous | View Threaded


eperez at yaco

Jun 27, 2010, 8:53 AM

Post #1 of 6 (1066 views)
Permalink
DirectoryViewSurrogate as context in FSPageTemplates

Hi

Here in Yaco, while migrating a plone-2.0 site to plone-4.0, we've hit a
problem with FSPageTemplates that live within a DirectoryViewSurrogate
(within a DirectoryViewSurrgate within a ...) whithin a DirectoryView.
The problem is that such a template gets as context the
DirectoryViewSurrogate whithin which it lives, and that such an object
doesn't get in its aq_inner.aq_parent chain the "real" context object on
which the template is called. As a consequence, browser components that
get rendered in macros surrounding or within the template get an
unexpected context, and bad things happen such as totally wrong
breadcrumbs, portlets not getting found by managers, wrong css class for
the body element of the produced html, etc.

My investigations, greatly helped by Hanno Schlichting (thanks again,
Hanno) on the plone-dev list, have led me to think that the problem lies
in the pt_getContext method of
Products.CMFCore.FSPageTemplate.FSPageTemplate. This method is directly
got from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate. IMHO,
that method makes sense in a PageTemplate living in the zodb, but not in
nested directories in the filesystem. So my proposed solution goes
through giving a special pt_getContext method to FSPageTemplate. The
requirements of that method would be:

* Provide a context that is the innermost DirectoryViewSurrogate, with
an aq_inner.aq_parent chain that directly passes from it to the "real"
context object on which the template is called. This way, "navigational"
elements such as the breadcrumbs get a proper path.

* Provide the intermediate DirectoryViewSurrogates in the aq_chain of
the final context. This way, if the FSPageTemplate relies by acquisition
on scripts or zsql methods or thigs like that that live in those
intermediate DVS, it will find them.

* Apply a similar logic to the container variable in the template? not
so sure about this, my stuff works with and without the c['container']
modification, so I have commented it out in the method below.

with this, I have come up with the following method for
Products.CMFCore.FSPageTemplate.FSPageTemplate:



from Products.CMFCore.interfaces import IDirectoryView
from Acquisition import aq_inner, aq_chain, aq_parent, aq_base

...

zpt_pt_getContext = ZopePageTemplate.pt_getContext.im_func

def pt_getContext(self, *args, **kwargs):
c = self.zpt_pt_getContext(*args, **kwargs)
if IDirectoryView.providedBy(c['context']):
context = c['context']
for obj in aq_chain(context):
if not IDirectoryView.providedBy(obj):
context = aq_base(context).__of__(obj)
break
#c['container'] =
c['container'].__of__(aq_parent(aq_inner(context)))
c['context'] = c['here'] = context.__of__(c['container'])
return c

(In my thunderbird getting the list from gmane the formatting gets
right, but just in case, I attach a diff file).

I have run the CMFCore tests on a
https://svn.plone.org/svn/plone/buildouts/plone-coredev/branches/3.3
buildout (not sure if it's the right place to run them) and they give
the same results with and without the patch, and commenting out or not
the container modification in the patch:


eperez [at] gallin$ ./bin/instance test -s Products.CMFCore
...
Error in test test_copy_cant_create_target_metatype_not_supported
...
Error in test test_move_cant_create_target_metatype_not_allowed
...
Error in test test_move_cant_create_target_metatype_not_supported
...
Total: 610 tests, 0 failures, 3 errors

So, questions:

Does this sound right? Is someone else encountering similar problems? If
the answer to the previous questions are yes and (yes or not), what
should be my next step?

Thanks for getting this far in this rather longish post.

Best regards,

--
Enrique Pérez Arnaud <eperez [at] yaco>
Yaco Sistemas SL| http://www.yaco.es
C/ Rioja 5, 41001 Sevilla (España)
Tel: (+34) 954 50 00 57
Fax 954 50 09 29
Attachments: fspagetemplate.pt_getContext.diff (1.53 KB)


charlie.clark at clark-consulting

Jun 27, 2010, 12:04 PM

Post #2 of 6 (1001 views)
Permalink
Re: DirectoryViewSurrogate as context in FSPageTemplates [In reply to]

Am 27.06.2010, 17:53 Uhr, schrieb Enrique Perez <eperez [at] yaco>:

> (In my thunderbird getting the list from gmane the formatting gets
> right, but just in case, I attach a diff file).
> I have run the CMFCore tests on a
> https://svn.plone.org/svn/plone/buildouts/plone-coredev/branches/3.3buildout
> (not sure if it's the right place to run them) and they give the same
> results with and without the patch, and commenting out or not the
> container modification in the patch:

Hi Enrique,

I'm not going to comment on the patch because I personally find the
context setting for templates a bit of black magic!

Regarding the best way to get a change done:

* file a bug on launchpad for Products.CMFCore

* check out Products.CMFCore from the main Zope repository:
svn:svn.zope.org://repos/main/CMF.buildout

* write a test for the case

* patch the source

* add the patch with the test to the launchpad bug

Recently we've been having regular bug days so there is a good chance that
the change will be included pretty quickly but I think this is heavily
dependent upon a test being included.

If I understand you correctly, you want to backport this to CMF 2.2 for
inclusion in Plone 4?

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


eperez at yaco

Jun 27, 2010, 4:00 PM

Post #3 of 6 (999 views)
Permalink
Re: DirectoryViewSurrogate as context in FSPageTemplates [In reply to]

Hi Charlie,

Thanks for your answer.

> Regarding the best way to get a change done:
>
> * file a bug on launchpad for Products.CMFCore
>
> * check out Products.CMFCore from the main Zope repository:
> svn:svn.zope.org://repos/main/CMF.buildout
>
> * write a test for the case
>
> * patch the source
>
> * add the patch with the test to the launchpad bug
>
> Recently we've been having regular bug days so there is a good chance that
> the change will be included pretty quickly but I think this is heavily
> dependent upon a test being included.

And thanks for your instructions (and for not just telling me to rtfm,
which I would have found fair enough), which I am in the process of
following up.

>
> If I understand you correctly, you want to backport this to CMF 2.2 for
> inclusion in Plone 4?
>

If at all possible, yes, so I will try to be as fast as I can with
writing the test.

Though I would like some comment on the container variable issue: I
don't find changing it strictly necessary, at least for my use case, but
without changing the container I don't feel that the semantic
relationship between context and container remains quite right.

Best regards,

--
Enrique Pérez Arnaud <eperez [at] yaco>
Yaco Sistemas SL| http://www.yaco.es
C/ Rioja 5, 41001 Sevilla (España)
Tel: (+34) 954 50 00 57
Fax 954 50 09 29

_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


hanno at hannosch

Jun 28, 2010, 3:27 AM

Post #4 of 6 (998 views)
Permalink
Re: DirectoryViewSurrogate as context in FSPageTemplates [In reply to]

On Mon, Jun 28, 2010 at 1:00 AM, Enrique Perez <eperez [at] yaco> wrote:
> Though I would like some comment on the container variable issue: I
> don't find changing it strictly necessary, at least for my use case, but
> without changing the container I don't feel that the semantic
> relationship between context and container remains quite right.

I think the container variable should be changed as well. You probably
don't see any problem as there's almost no code anywhere in
Zope/CMF/Plone that actually uses it. Most code does its own
aq_parent(context) calls.

Hanno
_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


eperez at yaco

Jun 28, 2010, 4:20 AM

Post #5 of 6 (1002 views)
Permalink
Re: DirectoryViewSurrogate as context in FSPageTemplates [In reply to]

Hi Hanno,

On 28/06/10 12:27, Hanno Schlichting wrote:
> I think the container variable should be changed as well. You probably
> don't see any problem as there's almost no code anywhere in
> Zope/CMF/Plone that actually uses it. Most code does its own
> aq_parent(context) calls.

Ok perfect, I will do it as you suggest.

I filled a bug in launchpad [1], I'll attach a patch once I manage to
write the test.


1.- https://bugs.launchpad.net/zope-cmf/+bug/599325

--
Enrique Pérez Arnaud <eperez [at] yaco>
Yaco Sistemas SL| http://www.yaco.es
C/ Rioja 5, 41001 Sevilla (España)
Tel: (+34) 954 50 00 57
Fax 954 50 09 29

_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests


eperez at yaco

Jul 5, 2010, 2:40 PM

Post #6 of 6 (955 views)
Permalink
Re: DirectoryViewSurrogate as context in FSPageTemplates [In reply to]

Hi Charlie

On 27/06/10 21:04, Charlie Clark wrote:

>
> Regarding the best way to get a change done:
>
> * file a bug on launchpad for Products.CMFCore
>
> * check out Products.CMFCore from the main Zope repository:
> svn:svn.zope.org://repos/main/CMF.buildout
>
> * write a test for the case
>
> * patch the source
>
> * add the patch with the test to the launchpad bug
>
> Recently we've been having regular bug days so there is a good chance that
> the change will be included pretty quickly but I think this is heavily
> dependent upon a test being included.

I've just (finally) done that, the issue is in

https://bugs.launchpad.net/zope-cmf/+bug/599325

Should I do something else, assign it to someone or something?

Thanks a lot!

--
Enrique Pérez Arnaud <eperez [at] yaco>
Yaco Sistemas SL| http://www.yaco.es
C/ Rioja 5, 41001 Sevilla (España)
Tel: (+34) 954 50 00 57
Fax 954 50 09 29

_______________________________________________
Zope-CMF maillist - Zope-CMF [at] zope
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests

Zope cmf RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.