本文介绍了如何将is_folderish属性添加到敏捷对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.is_folderish属性在许多地方使用.例如,当将对象设置为默认视图或在激活对象的讨论时.

The .is_folderish attribute is used in many places. For example when setting an object as the default view or when activating discussions on an object.

我的第一个问题是如何检查对象是否设置了该属性.我尝试将bin/instance debug与以下内容一起使用:

My first question is how to check is an object has that attribute set. I tried using the bin/instance debug with something like this:

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

我想我无法以这种方式到达属性,因为app.site.news是具有该属性的对象的包装.

I imagine that I can't reach attributes on that way because app.site.news is a wrapper to the object that has that attribute.

我的第二个问题是如何将该属性添加到新的敏捷对象中.我想我可以使用下面的代码来做到这一点(但是在解决第一个问题之前我无法对其进行测试).

My second question is how to add that attribute to a new Dexterity object. I suppose I can do it using the code below (but I can't test it before the my first question is resolved).

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

但是我不确定两个类如何链接.

But I'm not sure about how both classes could be linked.

推荐答案

您无需在类型中添加is_folderish;它是目录中的索引,并且敏捷类型已经具有该索引的适当属性isPrincipiaFolderish.

You don't need to add is_folderish to your types; it is an index in the catalog, and Dexterity types already have the proper attribute for that index, isPrincipiaFolderish.

如果要做需要向内容类型添加属性,则可以使用事件订阅者或创建plone.dexterity.content.Item的自定义子类:

If you do need to add attributes to content types, you can either use an event subscriber or create a custom subclass of 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类型中注册:

  • custom content classes need to be registered in your type XML:

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

    然后在Dexterity FTI XML文件中,添加klass属性:

    then in your Dexterity FTI XML file, add a klass property:

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

  • 这篇关于如何将is_folderish属性添加到敏捷对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-26 18:00