plon 使用什么规则来决定显示哪些菜单以及何时显示?

发布于 2024-11-24 21:21:45 字数 1979 浏览 0 评论 0原文

我正在使用 Plone 4.0.5,并且我花了一天时间试图理解 plone.app.contentmenu。

我有一个基于自定义文件夹的原型类型,并且我已经为其编写了一个视图。使用默认的 base_view (site/MyObject/base_view) 时,一切都会按预期工作。但使用我自己的自定义视图时,菜单开始消失,我一直无法弄清楚。

首先,我的 zcml,

<browser:page
  for="my.product.interfaces.IMyType"
  name="view"
  class="my.product.browser.mytype.MyTypeViewView"
  permission="zope.Public"
/>

视图本身尽可能简单:

class MyTypeViewView(BrowserView):
    template = ViewPageTemplateFile("templates/mytype_view.pt")
    def __call__(self):
        return self.template()

并且视图模板也被精简到什么都没有:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="plone">
<body>
<metal:content-core fill-slot="content-core">
  hi there.
</metal:content-core>
</body>
</html>

如果我访问 site/MyObject/view,模板显示“hi there”,但是 plone-contentmenu-actions 和克隆内容菜单工作流程消失。然而,plone-contentmenu-factories 仍然存在。如果我随后修改 ZCML 以设置 name="view_test",并访问 site/MyObject/view_test,则根本不会显示任何菜单。

对于这种类型,我有五个不同的视图,我希望工作流程菜单显示在所有视图上(或者至少显示我的主视图,以便我可以更轻松地进行测试,直到弄清楚)。

如果我将视图重命名为 base_view 并直接访问对象 URL,我仍然没有可用的工作流程菜单。

我想我的问题应该是:

plone 到底使用什么规则来决定显示哪些菜单以及何时显示?我应该阅读什么代码?

-- 编辑:

我已将此函数添加到我的视图中:

def __init__(self, context, request):
    super(MyTypeViewView, self).__init__(context, request)
    alsoProvides(self, IViewView)
    alsoProvides(self.context, IViewView)

如果我在 call 代码中放置一个断点,我会得到以下结果:

>>> IViewView.providedBy(self)
True
>>> IViewView.providedBy(self.context)
True

我很确定我只需要将 IViewView 应用于视图本身,但无论如何,这对我来说没有任何改变。

I'm using Plone 4.0.5, and I've spent the day trying to understand plone.app.contentmenu.

I have a custom folder based archetypes type, and I've written a view for it. When using the default base_view (site/MyObject/base_view), everything works as expected. Using my own custom view though, the menus start disappearing, and I haven't been able to figure it out.

First, my zcml,

<browser:page
  for="my.product.interfaces.IMyType"
  name="view"
  class="my.product.browser.mytype.MyTypeViewView"
  permission="zope.Public"
/>

The view itself is as simple as possible:

class MyTypeViewView(BrowserView):
    template = ViewPageTemplateFile("templates/mytype_view.pt")
    def __call__(self):
        return self.template()

And the view template has also been slimmed down to nothing:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="plone">
<body>
<metal:content-core fill-slot="content-core">
  hi there.
</metal:content-core>
</body>
</html>

If I access site/MyObject/view, the template shows "hi there", but plone-contentmenu-actions and plone-contentmenu-workflow disappear. plone-contentmenu-factories however, remains. if I then modify the ZCML to set name="view_test", and visit site/MyObject/view_test, none of the menus at all display.

I have five different views for this type, and I want the workflow menu to display on all of them (or at the very least, my main view, so that I can test more easily until I figure it out).

If I rename my view to base_view and visit the object URL directly, I still don't have a workflow menu available.

I guess my question should be:

What exactly are the rules plone works with to decide which menus to display, and when? What code should I be reading?

-- edit:

I've added this function to my View:

def __init__(self, context, request):
    super(MyTypeViewView, self).__init__(context, request)
    alsoProvides(self, IViewView)
    alsoProvides(self.context, IViewView)

if I place a breakpoint in my call code, I get this:

>>> IViewView.providedBy(self)
True
>>> IViewView.providedBy(self.context)
True

I'm pretty sure I only needed to apply IViewView to the view itself, but regardless, this doesn't change anything for me.

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

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

发布评论

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

评论(2

南冥有猫 2024-12-01 21:21:45

Plone 将 IViewView 标记接口应用于视图,该视图对于对象来说是规范的 - 您单击视图选项卡时得到的对象。界面的某些部分仅限于该界面 - 请参阅 http://plone.org/products/dexterity/documentation/manual/ Five.grok/browser-components/viewlets

Plone applied the IViewView marker interface to the view which are canonical for an object - the one you get clicking the view tab. Certain parts of the interface are restricted to that interface - see the section "Restricting a viewlet to the canonical view" in http://plone.org/products/dexterity/documentation/manual/five.grok/browser-components/viewlets

巷雨优美回忆 2024-12-01 21:21:45

由于您的页面已经有一个视图类(MyTypeViewView),因此更直接地使其实现接口,而不是使其实例提供它:

from plone.app.layout.globals.interfaces import IViewView

class MyTypeViewView(BrowserView):
    interface.implements(IViewView)

    ...

虽然我认为这不会解决您的问题,因为我确实有很多自定义视图不实现 IViewView 但可以很好地显示所有操作。

我想您只需将您的视图添加到 Portal_types 工具中您的类型的可用默认视图中就可以了。

Since you already have a view Class (MyTypeViewView) for your page it's more straight-forward to make it implement the interface instead of make instances of it provide it:

from plone.app.layout.globals.interfaces import IViewView

class MyTypeViewView(BrowserView):
    interface.implements(IViewView)

    ...

Although I think that this won't solve your problem since I do have lots of custom views that do not implement IViewView but display all actions nicely.

I guess you simply need to add your views to the available default views for your type in portal_types tool and you're fine.

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