避免删除对象(使用 IObjectWillBeRemovedEvent)并重定向到自定义视图/模板?
我想中止删除对象(自定义内容类型),并重定向到将工作流设置为名为 Unavailable
的自定义状态的页面(视图),向用户“您已成功删除该对象!”。该对象仍将位于 ZODB 上,但对于某些组来说,它根本看不到,就好像它真的被删除了一样。
我可以使用 IObjectWillBeRemovedEvent
在订阅者中进行加注,但尝试使用 raise zExceptions.Redirect("url")
不起作用。 raise
调用可以避免删除,但会显示一条消息“无法删除该对象”而不是重定向。
有人对这种情况有解决方案吗?
I would like to abort the deletion of an object (A custom Content-Type), and redirect to a page (a view) that sets the workflow to a custom state named Unavailable
, shows a message to the user "You succesfully deleted the object!". The object will still be on ZODB, but for some groups it'll simply not be seen, as if it was really deleted.
I can do a raise in a subscriber using IObjectWillBeRemovedEvent
, but trying to use raise zExceptions.Redirect("url")
doesn't work. The raise
call avoids the deletion, but a message "The object could not be deleted" is shown instead of the redirection.
Anyone has a solution to this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如你所看到的,Plone / Zope 2 的对象管理很混乱(是的,我愿意烧掉业力只是为了说这个)。您需要在用户界面级别(而不是对象级别)覆盖删除操作。
尝试弄清楚如何在 Plone 用户界面中自定义删除操作。
确保默认的删除操作不再可见且可用(例如为其设置更高的所需权限,例如 cmf.ManagePortal)
根据您的专业工作流程创建另一个删除操作
我相信可以从 Portal_actions 配置删除,但可能有单独的操作删除一个对象的情况(操作菜单)并删除多个对象(folder_contents)。
As you can see Plone / Zope 2 object management is messy (yes, I am willing to burn karma just to say this). You need to override delete action in the user interface level, not on the object level.
Try to figure out how to customize delete actions in Plone user interface.
Make sure the default Delete actions is no longer visible and available (e.g. set higher needed permission for it e.g. cmf.ManagePortal)
Create another Delete action which goes according to your specialized workflow
I believe Delete can be configured from portal_actions, but there might be separate cases for deleting one object (Actions menu) and deleting multiple objects (folder_contents).
您需要 REQUEST.response.redirect (“网址”)。我非常确定 zExceptions.Redirect 是 Zope 内部处理 response.redirect() 调用的方式。确保在调用redirect()之后仍然引发另一个异常,以便事务中止。
也就是说,这似乎是实现这一目标的错误方法。一方面,您将至少进行双重索引,这是在事务中止之前完成的。目录索引是处理修改内容的请求中最昂贵的部分,因此这会在服务器上造成浪费的负载。
事件用于执行与事件无关的附加操作。您想要的是从根本上改变某人删除时发生的情况。也许您应该修补/覆盖容器对象(文件夹?)上的底层删除方法来进行工作流转换。
You need REQUEST.response.redirect("url"). I'm pretty sure that zExceptions.Redirect is the way that Zope internally handles response.redirect() calls. Be sure you still raise another exception after calling redirect() so that the transaction is aborte.
That said, this sure seems like the wrong way to accomplish this. For one thing, you'll do at least double indexing, which is done before the transaction aborts. Catalog indexing is the most expensive part of processing a request that modifies content so this creates wasteful load on your server.
Events are for doing additional stuff which is only tangentially related to the event. What you want is to fundamentally change what happens when someone deletes. Maybe you should patch/override the underlying deletion method on the container objects (folders?) to do your worklfow transition.
您可以在事件处理程序中引发
OFS.ObjectManager.BeforeDeleteException
来停止删除。如果您引发LinkIntegrityNotificationException
,您将被重定向到 Plones 的良好链接完整性页面。You could raise a
OFS.ObjectManager.BeforeDeleteException
in the event handler to stop the deletion. If you raise aLinkIntegrityNotificationException
you get redirected to Plones nice Link intergrity page.