Customizing PSC
Emyr Thomas
emyr.thomas at gmail.com
Mon Aug 13 11:46:27 UTC 2007
Sorry for the rather long post, but I've tried to include all the required
info!
I'm adding some extra functionality to PloneSoftwareCenter for a project I'm
working on, and have developed a small package to do so. I'm trying to be as
non-invasive as possible, so am trying to use as much zope3 techniques as
possible, and not modifying the PSC code at all (only a couple of page
templates).
Basically, all software packages that go into this PSC instance require a
license key to activate, so I need some extra fields on the PSCRelease
object. I use an adapter (called License) to store the new fields as
attributes on the PSCRelese object. The adapter implements ILicense and
adapts ILicensable. It kind of works, but I've broken something since I
can't add new PSCRelease objects any more.
Here's my adapter code:
class License(object):
implements(ILicense)
adapts(ILicensable)
def __init__(self, context):
self.context = context
annotations = IAnnotations(context)
mapping = annotations.get(KEY)
if mapping is None:
blank = {'appname':'', ...}
mapping = annotations[KEY] = PersistentDict(blank)
self.mapping = mapping
def appname():
def get(self):
return self.mapping['appname']
def set(self, v):
self.mapping['appname'] = v
return property(get, set)
appname = appname()
And the ILicense schema looks like this:
class ILicense(Interface):
"""License settings for objects.
"""
appname = TextLine(
title=u'License mnemonic',
description=u'The appname of this release.',
required=False,
readonly=True
)
...
In my configure.zcml I have:
<class class="Products.PloneSoftwareCenter.content.release.PSCRelease">
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable
.interfaces.ILicensable"
/>
<require
permission="zope2.View"
interface=".interfaces.ILicense"
/>
<require
permission="zope2.ManageProperties"
set_schema=".interfaces.ILicense"
/>
</class>
<adapter
factory=".license.License"
trusted="true"
/>
<class class=".license.License">
<require
permission="zope2.View"
interface=".interfaces.ILicense"
/>
</class>
Trying to add a PSCRelease now gives the following traceback:
2007-08-13 10:25:28 ERROR Plone
Traceback (most recent call last):
File "/home/zope/instances/test/Products/CMFPlone/FactoryTool.py", line 147,
in __getitem__
self.invokeFactory(id=id, type_name=type_name)
File "/home/zope/instances/test/Products/CMFPlone/PloneFolder.py", line 406,
in invokeFactory
new_id = pt.constructContent(*args, **kw)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 934, in
constructContent
ob = info.constructInstance(container, id, *args, **kw)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 345, in
constructInstance
return self._finishConstruction(ob)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 357, in
_finishConstruction
ob.notifyWorkflowCreated()
File "/home/zope/instances/test/Products/CMFCore/CMFCatalogAware.py", line
145, in notifyWorkflowCreated
wftool.notifyCreated(self)
File "/home/zope/instances/test/Products/CMFCore/WorkflowTool.py", line 355,
in notifyCreated
wf.notifyCreated(ob)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
392, in notifyCreated
self._changeStateOf(ob, None)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
476, in _changeStateOf
sdef = self._executeTransition(ob, tdef, kwargs)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
571, in _executeTransition
self.updateRoleMappingsFor(ob)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
435, in updateRoleMappingsFor
if modifyRolesForPermission(ob, p, roles):
File "/home/zope/instances/test/Products/DCWorkflow/utils.py", line 60, in
modifyRolesForPermission
p.setRoles(roles)
File "/home/uknowhow/lib/Zope-2.9.7/lib/python/AccessControl/Permission.py",
line 93, in setRoles
else: attr=getattr(obj, name)
AttributeError: appname
/home/zope/instances/test/Products/CMFCore/TypesTool.py:278:
DeprecationWarning: getActionById() is deprecated and will be removed in CMF
2.0. Please use getActionInfo()['url'] if you need an URL or queryMethodID()
if you need a method ID.
DeprecationWarning)
2007-08-13 10:25:28 ERROR Plone
Traceback (most recent call last):
File "/home/zope/instances/test/Products/CMFPlone/FactoryTool.py", line 147,
in __getitem__
self.invokeFactory(id=id, type_name=type_name)
File "/home/zope/instances/test/Products/CMFPlone/PloneFolder.py", line 406,
in invokeFactory
new_id = pt.constructContent(*args, **kw)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 934, in
constructContent
ob = info.constructInstance(container, id, *args, **kw)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 345, in
constructInstance
return self._finishConstruction(ob)
File "/home/zope/instances/test/Products/CMFCore/TypesTool.py", line 357, in
_finishConstruction
ob.notifyWorkflowCreated()
File "/home/zope/instances/test/Products/CMFCore/CMFCatalogAware.py", line
145, in notifyWorkflowCreated
wftool.notifyCreated(self)
File "/home/zope/instances/test/Products/CMFCore/WorkflowTool.py", line 355,
in notifyCreated
wf.notifyCreated(ob)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
392, in notifyCreated
self._changeStateOf(ob, None)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
476, in _changeStateOf
sdef = self._executeTransition(ob, tdef, kwargs)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
571, in _executeTransition
self.updateRoleMappingsFor(ob)
File "/home/zope/instances/test/Products/DCWorkflow/DCWorkflow.py", line
435, in updateRoleMappingsFor
if modifyRolesForPermission(ob, p, roles):
File "/home/zope/instances/test/Products/DCWorkflow/utils.py", line 60, in
modifyRolesForPermission
p.setRoles(roles)
File "/home/uknowhow/lib/Zope-2.9.7/lib/python/AccessControl/Permission.py",
line 93, in setRoles
else: attr=getattr(obj, name)
AttributeError: appname
2007-08-13 10:25:28 ERROR Zope.SiteErrorLog
http://localhost:8080/test/products/test-product/releases/portal_factory/PSCRelease/1.0/atct_edit
Traceback (innermost last):
Module ZPublisher.Publish, line 115, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 41, in call_object
Module Products.CMFPlone.FactoryTool, line 361, in __call__
Module Products.CMFPlone.FactoryTool, line 147, in __getitem__
Module Products.CMFPlone.PloneFolder, line 406, in invokeFactory
Module Products.CMFCore.TypesTool, line 934, in constructContent
Module Products.CMFCore.TypesTool, line 345, in constructInstance
Module Products.CMFCore.TypesTool, line 357, in _finishConstruction
Module Products.CMFCore.CMFCatalogAware, line 145, in notifyWorkflowCreated
Module Products.CMFCore.WorkflowTool, line 355, in notifyCreated
Module Products.DCWorkflow.DCWorkflow, line 392, in notifyCreated
Module Products.DCWorkflow.DCWorkflow, line 476, in _changeStateOf
Module Products.DCWorkflow.DCWorkflow, line 571, in _executeTransition
Module Products.DCWorkflow.DCWorkflow, line 435, in updateRoleMappingsFor
Module Products.DCWorkflow.utils, line 60, in modifyRolesForPermission
Module AccessControl.Permission, line 93, in setRoles
AttributeError: appname
Also, when zope starts up, I get this warning:
2007-08-13 10:24:09 WARNING Init Class
Products.PloneSoftwareCenter.content.release.PSCRelease has a security
declaration for nonexistent method 'appname'
I'm not sure what I'm doing wrong, can anyone offre some advice?
Thanks
Emyr
More information about the Product-Developers
mailing list