Zope 2:将manage_addProduct与自己的产品一起使用(AttributeError)

时间:2013-01-07 12:38:46

标签: zope

我是Zope 2编程世界的新手。如果我问一些明显的东西,请耐心等待。

我创建了一个示例产品。在ZMI中一切都很好:我可以轻松添加/删除产品并更改其属性。但是我无法在代码中添加产品或使用Zope调试模式。我一遍又一遍地阅读OFS.Folder代码(作为参考),发现任何差异都无济于事。

如果有人能给我一些提示/线索,我真的很感激。 TIA,

产品代码:

##
## bahmanm.devistan.implementation.Devistan
##
from bahmanm.devistan.interfaces import IDevistan
from zope.interface import implements
from OFS.Folder import Folder
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Acquisition import Implicit
from Globals import Persistent, InitializeClass
from AccessControl.Role import RoleManager
from OFS.ObjectManager import ObjectManager
from OFS.PropertyManager import PropertyManager
from OFS.FindSupport import FindSupport


class Devistan(Implicit, Persistent, RoleManager, Folder):
    """Devistan product implementation.
    """
    implements(IDevistan)
    meta_type = 'Devistan Site'
    _properties = ({'id': 'title', 'type': 'string', 'mode': 'wd'},)
    manage_options = (
        ObjectManager.manage_options +
        ({'label': 'View', 'action': ''}, ) +
        PropertyManager.manage_options +
        RoleManager.manage_options +
        Folder.manage_options +
        FindSupport.manage_options
        )
    index_html = PageTemplateFile(
        '../template/devistan/index.pt', globals())

    def __init__(self, id=None):
        if id is not None:
            self.id = str(id)

InitializeClass(Devistan)


manage_addDevistanForm = PageTemplateFile(
    '../template/devistan/manage_addDevistanForm.pt', globals())


def manage_addDevistan(self, id, title='', REQUEST=None):
    """Adds a new Devistan instance.
    """
    obj = Devistan(id)
    obj.title = title
    self._setObject(id, obj)
    if REQUEST is not None:
        return self.manage_main(self, REQUEST, update_menu=1)
    return "<p>Devistan instance successfully installed: <tt>%s</tt>" % id


def initialize(self):
    self.registerClass(
        Devistan,
        constructors=(manage_addDevistanForm,
                      manage_addDevistan))

__init__.py代码:

##
## bahman.devistan.__init__.py
##
from bahmanm.devistan.implementation import Devistan


def initialize(self):
    """Registers Devistan product.
    """
    Devistan.initialize(self)

从示例页面调用manage_addDevistan时的堆栈跟踪:

2013-01-07 15:43:11 ERROR Zope.SiteErrorLog 1357560791.840.323411816939 http://localhost:8080/devistan/addSampleSite
Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module bahmanm.devistan.implementation.Devistan, line 37, in addSampleSite

Zope调试模式中的输出:

>>> app.manage_addProduct['Devistan'].manage_addDevistan
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: manage_addDevistan

buildout.cfg:

[buildout]
parts = zope2
        instance
extends = http://download.zope.org/Zope2/index/2.13.19/versions.cfg
develop = /home/bahman/Work/devistan/bahmanm.devistan

[zope2]
recipe = zc.recipe.egg
eggs = Zope2
       bahmanm.devistan
interpreter = zopepy
debug-mode = on

[instance]
debug-mode = on
recipe = plone.recipe.zope2instance
user = admin:admin
http-address = 8080
eggs = ${zope2:eggs}
zcml = bahmanm.devistan

1 个答案:

答案 0 :(得分:1)

要添加产品,只需直接导入manage_addDevistan功能:

from bahmanm.devistan.implementation import manage_addDevistan

manage_addDevistan(somefolder, 'someid')
相关问题