跳转到主要内容

启用内容类型实例的行为。

项目描述

collective.instancebehavior

问题和动机

plone.behavior 包提供的功能,为扩展Dexterity内容类型的函数提供了一种非常有用的方法。不幸的是,内容类型的行为存储在portal_types工具内部的内容工厂信息(FTI)中,意味着它们是类(或类型)特定的,而不是实例特定的。这意味着行为只能全局启用,换句话说,只能为特定类型的所有实例启用。

要启用每个实例的行为,我们需要一种在实例上存储这些行为的方法。我们使用注解来达到这个目的。

此外,我们还提供自己的 IBehaviorAssignable 适配器,它覆盖了默认适配器。它不仅查找对象的FTI注册注解,还查找当前实例注解中存储的行为。

还实现了辅助函数,可以在Dexterity内容对象上动态分配行为和接口。

安装

将您的Plone插件依赖项设置为 collective.instancebehavior

启用行为和接口

注意:目标对象必须实现 collective.instancebehavior.IInstanceBehaviorAssignableContent

>>> from plone.app.event.dx.interfaces import IDXEvent
>>> enable_behaviors(
...     obj,
...     ['plone.app.event.dx.behaviors.IEventBasic',],
...     [IDXEvent,]
... )

禁用行为和接口

>>> from plone.app.event.dx.interfaces import IDXEvent
>>> disable_behaviors(
...     obj,
...     ['plone.app.event.dx.behaviors.IEventBasic',],
...     IDXEvent,]
... )

想法

参考

  • http://opkode.net/media/blog/plone-and-dexterity-enable-behaviors-per-content-type-instance

  • https://gist.github.com/thet/3990769

来自IRC

12:13 < rnix> datakurre: https://github.com/bluedynamics/bda.plone.productshop/blob/master/bda/plone/productshop/browser/forms.py
12:13 < rnix> datakurre: woring instance behavior enabled add form
12:21 < rnix> datakurre: may be generalized to collective.instancebehavior -> just need a generic way on telling DX to use the correct form. -> idea would be to have a
              behavior which can be bound to folderish objects and this defined default behaviors applied dynamically
12:21 < rnix> to it's direct children
12:22 < rnix> but i do not really like to register this add view for every type.. would be more appropriate if we found a way on
12:22 < rnix> deciding by applied container interface
12:22 < rnix> something like that...
12:26 < datakurre> rnix: What the differences for original add form? 1) show fields for default instance behaviors 2) enable default instance behaviors on save?
12:28 < datakurre> rnix: 2) Could probably be done by instancebehavior-adapter (add form would call it, when instancebehavior-behavior is enabled)
12:28 < datakurre> rnix: 1) migth be possible with plone.z3cform's FormExtender
12:30 < rnix> datakurre: i was thinking of an IChildDefaultInstanceBehaviors behavior, which reads the available IInstanceBehavior deriving definitions. and sets them to
              all added children by default
12:30 < rnix> the add view can then be bound to IChildDefaultInstanceBehaviors
12:31 < datakurre> rnix: Well, that works for sure.
12:32 < rnix> datakurre: instead of binding the add view by name to Products.CMFCore.interfaces.IFolderish, we bind it to IChildDefaultInstanceBehaviors without name...

支持

我们感谢任何贡献,如果需要在PyPI上发布版本,请直接联系任何一位贡献者。我们中的一些人也提供商业支持,如果您需要培训、辅导、集成或定制。

如果您遇到问题,请告诉我们。

源代码

源代码在GIT DVCS中,主要分支位于 github。在那里您也可以报告问题。

我们很高兴看到许多分支和pull请求,以使此插件变得更好。

此包使用 black 代码风格

贡献者

  • JC Brand

  • Johannes Raggam

  • Robert Niederreiter

  • Peter Holzer

  • Jens Klein

许可协议

本项目受GPLv2许可。

变更日志

0.5

  • 使全局模式缓存无效 [jensens]

  • Black代码风格,isort导入,总体维护 [jensens]

0.4

  • 在依赖关系和其他egg改进上更加明确 [tomgross]

0.3

  • 修复 DexterityInstanceBehaviorAssignable.enumerateBehaviors 以支持 plone.dexterity >= 2.3.0 [agitator]

0.2

  • 在连接之前将 enable_behaviors 中的行为转换为元组 [rnix]

  • 在添加之前检查实例行为是否已在实例行为中 [rnix]

0.1

  • 基于jcbrand和thet的工作创建了 collective.instancebehavior [rnix]

  • 使用通用辅助函数改进了实现 [thet]

  • 问题描述和初始实现 [jcbrand]

许可协议

版权(c)2013,JC Brand,Johannes Raggam,Robert Niederreiter 所有权利保留。

在不违反以下条件的情况下,允许重新分发和使用源代码和二进制形式,无论是否修改:

  • 源代码重新分发必须保留上述版权声明、本许可列表和以下免责声明。

  • 二进制形式的重新分发必须在不修改的情况下复制上述版权声明、本许可列表和以下免责声明,在随附的文档和其他材料中。

  • 未经事先书面许可,不得使用BlueDynamics Alliance的名称或其贡献者的名称来认可或推广由此软件派生出的产品。

本软件由BlueDynamics Alliance提供,按“原样”提供,任何明示或暗示的保证,包括但不限于适销性和针对特定目的的适用性保证,均被排除。在任何情况下,BlueDynamics Alliance不对任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,即使已被告知此类损害的可能性,无论责任基于合同、严格责任或侵权(包括疏忽或其他)。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码发行版

collective.instancebehavior-0.5.tar.gz (13.6 kB 查看哈希值)

上传于 来源

支持者