我是Zope2编程领域的新手。所以,如果我问的是明显的问题,请耐心等待。
我创建了一个示例产品。在ZMI中一切都很好:我可以轻松地添加/删除产品并更改其属性。但是,我不能在代码中或使用Zope调试模式添加产品。我一遍又一遍地阅读OFS.Folder代码(作为参考),找出任何不同之处都无济于事。
如果有人能给我一点提示,我将不胜感激。蒂娅
产品代码:
##
## 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 addSampleSiteZope调试模式下的输出:
>>> app.manage_addProduct['Devistan'].manage_addDevistan
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: manage_addDevistanbuildout.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发布于 2013-01-08 03:07:41
要添加您的产品,只需直接导入manage_addDevistan函数:
from bahmanm.devistan.implementation import manage_addDevistan
manage_addDevistan(somefolder, 'someid')https://stackoverflow.com/questions/14196149
复制相似问题