¿Cómo enumerar los nombres de las vistas en Plone 4 para una interfaz específica?

Is there any simple way in zope component system to list all views (and their names), which were registered for specific interface (eg IMyInterface):

<browser:page
  name="content-item-plain"
  for=".interfaces.IMyInterface"
  class=".content_item.MyView"
  permission="zope2.View"
  layer="my.model.browser.interfaces.IMyModelLayer"
  template="templates/content_item_plain.pt"
/>
class MyView(BrowserView):
    implements(ISomeInterface)

Or, even better, those, which implement certain interface (ISomeInterface)?

The result should be list/tuple of classes (MyView, MyView1, ...) and/or names ("content-item-plain", ...).

There is no problem to add classImplements/classProvides to the MyView class, if it helps.

Many things tried so far. The nearest is this:

from zope.component import getGlobalSiteManager
gsm = getGlobalSiteManager()
gsm.adapters.lookupAll((IMyInterface, IMyModelLayer), provided=Interface))

but it gives too many results and changing provided to something more specific makes it return empty tuple.

With results it should be possible to lookup view class attributes.

preguntado el 02 de febrero de 12 a las 10:02

1 Respuestas

Sí.

Get the list:

http://docs.plone.org/develop/plone/views/browserviews.html#listing-available-views

And filter it out in a way you wish.

contestado el 07 de mayo de 14 a las 18:05

Thanks for the answer. I have no choice but accept it, because now it seems to me that there is no "magic" method to find those views without alittle bit of further filtering. In addition to what is said in the docs, I can use my layer to constraint the number of views: registration.getViews(IMyLayer) and then filter. - Roman Susi

link is broken.. please fix - sureshvv

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.