如何列出 Plone 4 中特定接口的视图名称?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
获取列表:
http://docs.plone.org /develop/plone/views/browserviews.html#listing-available-views
并以您希望的方式将其过滤掉。
Yes.
Get the list:
http://docs.plone.org/develop/plone/views/browserviews.html#listing-available-views
And filter it out in a way you wish.