-->

如何将is_folderish属性添加到敏捷的对象?(How to add the is_folde

2019-10-17 18:04发布

.is_folderish属性在很多地方使用。 例如,当设置一个对象作为默认视图或当激活在物体上的讨论 。

我的第一个问题是如何检查的对象有一个属性设置。 我尝试使用bin/instance debug像这样的东西:

>>> app.site.news.is_folderish
...
AttributeError: is_folderish

我想,因为我不能就这样属性app.site.news是一个包装到具有属性的对象。

我的第二个问题是如何在属性添加到一个新的敏捷对象。 我想我可以用下面的代码做(但我不能测试它的我的第一个问题解决之前)。

from zope import schema
from plone.dexterity.content import Item

class IHorse(form.Schema):
    ...

class Horse(Item):
    def __init__(self):
        super(Horse, self).__init__(id)
        is_folderish = False

但我不知道这两个类是如何被联系起来。

Answer 1:

你并不需要添加is_folderish到您的类型; 它是在目录中的索引,敏捷类型已经为该指数,适当的属性isPrincipiaFolderish

如果确实需要将属性添加到内容类型,您可以使用事件的用户或创建一个自定义子类plone.dexterity.content.Item

  • 用户可以监听IObjectCreatedEvent事件:

     from zope.app.container.interfaces import IObjectAddedEvent @grok.subscribe(IYourDexterityType, IObjectCreatedEvent) def add_foo_attribute(obj, event): obj.foo = 'baz' 
  • 自定义内容类需要在你的XML类型登记:

     from plone.dexterity.content import Item class MyItem(Item): """A custom content class""" ... 

    然后在你的敏捷FTI XML文件,添加一个klass属性:

     <property name="klass">my.package.myitem.MyItem</property> 


文章来源: How to add the is_folderish attribute to Dexterity objects?