portlet metadata and availability of portlet renderers

classic Classic list List threaded Threaded
5 messages Options
Enrique Pérez Arnaud Enrique Pérez Arnaud
Reply | Threaded
Open this post in threaded view
|

portlet metadata and availability of portlet renderers

Hi,

This is in relation to a problem posted to the product-developers list
(http://article.gmane.org/gmane.comp.web.zope.plone.product-developers/5050).
I hope this is the correct place to raise this issue, otherwise, sorry.

The issue is being able to access the __portlet_metadata__ of a renderer
to determine its availability. My use case is overriding the renderer of
the events portlet in plone.app.portlets so that it will only show
events in the container subtree starting where the portlet is
(contextually) assigned. My wish/guess is to access the root of that
subtree from the renderer.__portlet_metadata__['key'].

However, the
plone.portlets.manager.PortletManagerRenderer._lazyLoadPortlets method
checks the availability of the renderer before setting the
__portlet_metadata__ field on it. So I would propose a patch like (I
attach the patch in case it does not render properly):

--- plone/portlets/manager.py.orig      2010-07-06 13:35:53.000000000 +0200
+++ plone/portlets/manager.py   2010-07-06 13:04:34.000000000 +0200
@@ -104,6 +104,13 @@
          items = []
          for p in self.filter(retriever.getPortlets()):
              renderer = self._dataToPortlet(p['assignment'].data)
+            info = p.copy()
+            info['manager'] = self.manager.__name__
+            info['renderer'] = renderer
+            hashPortletInfo(info)
+            # Record metadata on the renderer
+            renderer.__portlet_metadata__ = info.copy()
+            del renderer.__portlet_metadata__['renderer']
              try:
                  isAvailable = renderer.available
              except ConflictError:
@@ -115,16 +122,7 @@
                      "(%r %r %r): %s" % (
                      p['category'], p['key'], p['name'], str(e)))
              if isAvailable:
-                info = p.copy()
-                info['manager'] = self.manager.__name__
-                info['renderer'] = renderer
-                hashPortletInfo(info)
                  items.append(info)
-
-                # Record metadata on the renderer
-                renderer.__portlet_metadata__ = info.copy()
-                del renderer.__portlet_metadata__['renderer']
-
          return items

      def _dataToPortlet(self, data):

It is doing a little more work when a portlet renderer is not available,
but it is fairly unexpensive. The tests all run the same with and
without the patch (in a buildout from
http://svn.plone.org/svn/plone/buildouts/plone-coredev/branches/4.0,
plone.portlets-2.0b2-py2.6, python 2.6.5):

without the patch:
------------------


eperez@gallina$ bin/test -m plone.portlets
....
   Ran 57 tests with 0 failures and 0 errors in 0.566 seconds.

eperez@gallina$ bin/test -m plone.app.portlets
....
Total: 169 tests, 0 failures, 0 errors in 36.515 seconds.

eperez@gallina$ bin/test
....
Total: 3234 tests, 62 failures, 142 errors in 5 minutes 7.627 seconds.

with the patch:
---------------


eperez@gallina$ bin/test -m plone.portlets
....
Ran 57 tests with 0 failures and 0 errors in 0.579 seconds.

eperez@gallina$ bin/test -m plone.app.portlets
....
Total: 169 tests, 0 failures, 0 errors in 36.362 seconds.

eperez@gallina$ bin/test
....
Total: 3234 tests, 62 failures, 142 errors in 5 minutes 26.502 seconds.


Does all this sound sensible? Should I raise an issue in the tracker?

Thanks for listening, and best regards.


--
Enrique Pérez Arnaud <[hidden email]>
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

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers

plone.portlets.manager.patch (1K) Download Attachment
Hanno Schlichting-4 Hanno Schlichting-4
Reply | Threaded
Open this post in threaded view
|

Re: portlet metadata and availability of portlet renderers

Hi.

On Tue, Jul 6, 2010 at 2:06 PM, Enrique Perez <[hidden email]> wrote:

> However, the plone.portlets.manager.PortletManagerRenderer._lazyLoadPortlets
> method checks the availability of the renderer before setting the
> __portlet_metadata__ field on it. So I would propose a patch like (I attach
> the patch in case it does not render properly):
>
> --- plone/portlets/manager.py.orig      2010-07-06 13:35:53.000000000 +0200
> +++ plone/portlets/manager.py   2010-07-06 13:04:34.000000000 +0200
> @@ -104,6 +104,13 @@
>         items = []
>         for p in self.filter(retriever.getPortlets()):
>             renderer = self._dataToPortlet(p['assignment'].data)
> +            info = p.copy()
> +            info['manager'] = self.manager.__name__
> +            info['renderer'] = renderer
> +            hashPortletInfo(info)
> +            # Record metadata on the renderer
> +            renderer.__portlet_metadata__ = info.copy()
> +            del renderer.__portlet_metadata__['renderer']
>             try:
>                 isAvailable = renderer.available
>             except ConflictError:
> @@ -115,16 +122,7 @@
>                     "(%r %r %r): %s" % (
>                     p['category'], p['key'], p['name'], str(e)))
>             if isAvailable:
> -                info = p.copy()
> -                info['manager'] = self.manager.__name__
> -                info['renderer'] = renderer
> -                hashPortletInfo(info)
>                 items.append(info)
> -
> -                # Record metadata on the renderer
> -                renderer.__portlet_metadata__ = info.copy()
> -                del renderer.__portlet_metadata__['renderer']
> -
>         return items
>
>     def _dataToPortlet(self, data):

The patch looks reasonable to me. Maybe Martin has an opinion?

> eperez@gallina$ bin/test -m plone.app.portlets
> ....
> Total: 169 tests, 0 failures, 0 errors in 36.515 seconds.

If you want to run tests for a package, it's actually:

bin/test -s plone.app.portlets

-m works a bit by accident.

> eperez@gallina$ bin/test
> ....
> Total: 3234 tests, 62 failures, 142 errors in 5 minutes 7.627 seconds.

To run all tests in the coredev buildout, you can use:

bin'alltests

This runs the tests for one package at a time and avoids the test
interference issues you get with bin/test. Maybe one day one everyone
is using plone.app.testing we will get back proper test isolation and
can run everything at once again.

Hanno

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers
Enrique Pérez Arnaud Enrique Pérez Arnaud
Reply | Threaded
Open this post in threaded view
|

Re: portlet metadata and availability of portlet renderers

Hi.

On 06/07/10 14:15, Hanno Schlichting wrote:

>
> If you want to run tests for a package, it's actually:
>
> bin/test -s plone.app.portlets
>
> To run all tests in the coredev buildout, you can use:
>
> bin'alltests
>

Hanno, thanks a lot for the info. I'm rather ignorant in these issues,
and am sorry for not rtfm. I'm attaching now the patch with a test (the
patch is against plone.portlets trunk, r37671). My test fails without
the patch to manager.py, and succeeds with it, and the rest of the tests
of that package (plone.portlets) succeed with the patch. I haven't
tested any more packages, because I updated the coredev plone 4.0
buildout and run into problems with PIL, and it's rather late tonight to
start fighting with PIL.

If Martin Aspeli or someone authoritative on this matter agrees, I'll
open an issue in the tracker and attach the patch.

Best regards,

--
Enrique Pérez Arnaud <[hidden email]>
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

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers

plone.portlets.manager.patch (5K) Download Attachment
Alexander Limi Alexander Limi
Reply | Threaded
Open this post in threaded view
|

Re: portlet metadata and availability of portlet renderers

On Tue, Jul 6, 2010 at 3:19 PM, Enrique Perez <[hidden email]> wrote:
If Martin Aspeli or someone authoritative on this matter agrees, I'll open an issue in the tracker and attach the patch.

Opening a ticket and attaching a patch is always appropriate. If you want, add "optilude" to the CC field to make sure it's on Martin's radar.

--
Alexander Limi · http://limi.net

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers
Alexander Limi · http://limi.net

Enrique Pérez Arnaud Enrique Pérez Arnaud
Reply | Threaded
Open this post in threaded view
|

Re: portlet metadata and availability of portlet renderers

Thanks for your answer Alex,

On 12/07/10 20:15, Alexander Limi wrote:
>
> Opening a ticket and attaching a patch is always appropriate. If you
> want, add "optilude" to the CC field to make sure it's on Martin's radar.
>

Just did that, ticket #10742 [1].

1. https://dev.plone.org/plone/ticket/10742

--
Enrique Pérez Arnaud <[hidden email]>
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


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plone-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-developers