Re: Removing "layout" property — AttributeError: manage_delProperty

David Siedband <[email protected]>
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
Hi Dieter,

On Aug 22, 2014, at 3:24 AM, dieter <[email protected]> wrote:

> David Siedband <[email protected]> writes:
>> ...
>> So, I created a script which looks like this:
>> 
>> = = = = = = = = = 
>> from Products.CMFCore.utils import getToolByName
>> 
>> plone_utils = getToolByName(context, 'plone_utils')
>> r = context.REQUEST
>> 
>> obj = context.aq_explicit
>> 
>> if obj.hasProperty('layout'):
>>   obj.manage_delProperty('layout')
>>   plone_utils.addPortalMessage(_(u'The layout property has been deleted.'), 'info')
>> else:
>>  plone_utils.addPortalMessage(_(u'This object has no layout property.'), 'info')
>> 
>> return r.RESPONSE.redirect(obj.absolute_url())
>> = = = = = = = = = 
>> 
>> When I run the script I get the following error about "AttributeError: manage_delProperty"
>> 
>> Traceback (innermost last):
>>  Module ZPublisher.Publish, line 138, in publish
>>  Module ZPublisher.mapply, line 77, in mapply
>>  Module ZPublisher.Publish, line 48, in call_object
>>  Module Shared.DC.Scripts.Bindings, line 322, in __call__
>>  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
>>  Module Products.PythonScripts.PythonScript, line 344, in _exec
>>  Module script, line 10, in resetLayout
>>   - <PythonScript at /portal/resetLayout used for /portal/data/regional-geo-data/invertebrates>
>>   - Line 10
>> AttributeError: manage_delProperty
> 
> "OFS.PropertyManager.PropertyManager" has the method
> "manage_delProperties" (but no "manage_delProperty").


That did it, thanks.  I had stumbled upon this thread which erroneously mentions a “manage_delProperty” method
http://copilotco.com/mail-archives/plone-users.2005/msg00287.html

It took me a moment to figure out that this method expects a list.  For anyone referring to this thread, the syntax that worked for me was:
obj.manage_delProperties(('layout',))

Also, in my example code I had neglected to import the PloneMessageFactory, so I also had to add the following at the top of my script
from Products.CMFPlone import PloneMessageFactory as _

--
David Siedband
http://zentraal.com


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.