Error trying to modify data with python code in plone
Kaminie Amarjit <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <7C7A41B7E1CB554A812ACC789E32865401F2154303@EXCHMB5.yorkcollege.local> |
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<http://172.16.140.23:8080/yc1/error_log/getLogEntryAsText?id=1435073426.330.969255523092>
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
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Plone-developers mailing list
Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/plone-developers