Hi,
I am new to Plone. I have some python code written to modify data and I am getting errors.
The line that produces the error is
obj.setLast_name2()
The error is
• <PythonScript at /yc1/test2>
Line 38
• Module AccessControl.ImplPython, line 675, in guarded_getattr
AttributeError: setLast_name2
I have been googling this and I came across something that said you have to use an external method to have full permissions to run certain code. Later I came across another posting that said external methods are obsolete and one should use views. I am quite confused right now. Can someone point me in the right direction and how I should go about doing it?
Full Python code:
from AccessControl import getSecurityManager
from StringIO import StringIO
from Products.CMFCore.utils import getToolByName
membership = getToolByName(context, 'portal_membership')
username = context.portal_membership.getAuthenticatedMember().getUserName()
print username
buf = StringIO()
itemp = context.portal_catalog.queryCatalog({
"portal_type":("Staff","Faculty"),
"path":"/yc1/portal_college/rnunez",
"sort_on" : "created" })
items = list(itemp)
context.manage_setLocalRoles(username, ['Manager', 'Owner','Editor'])
#context.manage_permission('Edit', roles=['Manager', 'Owner','Editor'], acquire=True)
print >> buf, "Found %d items to be Updated" % len(items)
getSecurityManager().checkPermission('View', context)
roles2 = [r['name'] for r in context.rolesOfPermission('View') if r['selected']]
#context.portal.rolesOfPermission('Modify portal content')
count = 0
for b in items:
count += 1
obj = b.getObject()
#obj.declareObjectPublic() # like roles = ACCESS_PUBLIC
#print >> buf, "updating:" + obj.absolute_url()
#obj.at_post_edit_script
m=obj.getLast_name()
print m
obj.setLast_name2()
m=obj.getLast_name()
print m
return buf.getvalue(), printed
Full Error:
We’re sorry, but there seems to be an error…
Here is the full error message:
Display traceback as text
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 38, in test2
<PythonScript at /yc1/test2>
Line 38
• Module AccessControl.ImplPython, line 675, in guarded_getattr
AttributeError: setLast_name2