如何列出 Plone 4 中特定接口的视图名称?

发布于 2025-01-01 22:27:39 字数 1011 浏览 4 评论 0原文

zope组件系统中是否有任何简单的方法来列出为特定接口(例如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)

或者更好的是,那些实现特定接口(ISomeInterface)的视图?

结果应该是类(MyView、MyView1、...)和/或名称(“content-item-plain”、...)的列表/元组。

如果有帮助的话,将 classImplements/classProvides 添加到 MyView 类是没有问题的。

到目前为止尝试了很多事情。最接近的是:

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

但它给出了太多结果,并且将 provided 更改为更具体的内容会使其返回空元组。

通过结果应该可以查找视图类属性。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2025-01-08 22:27:39

是的。

获取列表:

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

并以您希望的方式将其过滤掉。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文