避免删除对象(使用 IObjectWillBeRemovedEvent)并重定向到自定义视图/模板?

发布于 2024-11-30 03:19:53 字数 337 浏览 2 评论 0原文

我想中止删除对象(自定义内容类型),并重定向到将工作流设置为名为 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 技术交流群。

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

发布评论

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

评论(3

挽清梦 2024-12-07 03:19:53

正如你所看到的,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).

夏日浅笑〃 2024-12-07 03:19:53

您需要 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.

沉睡月亮 2024-12-07 03:19:53

您可以在事件处理程序中引发 OFS.ObjectManager.BeforeDeleteException 来停止删除。如果您引发 LinkIntegrityNotificationException,您将被重定向到 Plones 的良好链接完整性页面。

from OFS.interfaces import IObjectWillBeRemovedEvent
from plone.app.linkintegrity.exceptions import LinkIntegrityNotificationException
import grok

@grok.subscribe(ICSRDocument, IObjectWillBeRemovedEvent)
def document_willbemoved(doc, event):
    raise LinkIntegrityNotificationException(doc)

You could raise a OFS.ObjectManager.BeforeDeleteException in the event handler to stop the deletion. If you raise a LinkIntegrityNotificationException you get redirected to Plones nice Link intergrity page.

from OFS.interfaces import IObjectWillBeRemovedEvent
from plone.app.linkintegrity.exceptions import LinkIntegrityNotificationException
import grok

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