1

我是 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
4

1 回答 1

2

要添加您的产品,只需直接导入manage_addDevistan函数:

from bahmanm.devistan.implementation import manage_addDevistan

manage_addDevistan(somefolder, 'someid')
于 2013-01-07T19:07:40.523 回答