Re: Error trying to modify data with python code in plone
espen <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <[email protected]> |
> 23. jun. 2015 kl. 18.23 skrev Kaminie Amarjit [via Plone] <ml-node+s293351n7574026h59-PKuAHvtXa09l57MIdRCFDg@public.gmane.org>:
>
> 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()
>
If you make a browser view, I think you should be all right
For that, you will need a zcml file with something like this:
https://github.com/espenmn/medialog.redirect/blob/master/src/medialog/redirect/browser/configure.zcml <https://github.com/espenmn/medialog.redirect/blob/master/src/medialog/redirect/browser/configure.zcml>
(but please, change the «permissions» line)
Then you need the view itself, like this (but with your code):
https://github.com/espenmn/medialog.redirect/blob/master/src/medialog/redirect/browser/view.py <https://github.com/espenmn/medialog.redirect/blob/master/src/medialog/redirect/browser/view.py>
If that too sound too complicated, try downloading the whole product and
1) Search & replace ‘medialog’ with ‘your name’ and
2) search & replace ‘redirect’ with ‘yourproductname’ in files and filename
3) Open every file, one by one, you will like be able to guess if anything should be changed
4) Put your add-on ( your name.yourproductname) in /src folder
5) Add egg = yourname.productname and src = src/yourname.productname to buildout.cfg
6) Run bin/buildout
7) (re)start phone and
8) install the add-on
9) run the browser view ( http://site/@@browserviewname <http://site/@@browserviewname>)
( or you could read ‘everything about browser views and do it ‘properly’)
PS: I am not a ‘python expert, so if other have suggestions, that is probably better .
Espen
>
>
> 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 <http://ad.doubleclick.net/ddm/clk/292181274;119417398;o>
> _______________________________________________
> Plone-developers mailing list
> [hidden email] <x-msg://2/user/SendEmail.jtp?type=node&node=7574026&i=0>
> https://lists.sourceforge.net/lists/listinfo/plone-developers <https://lists.sourceforge.net/lists/listinfo/plone-developers>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://plone.293351.n2.nabble.com/Error-trying-to-modify-data-with-python-code-in-plone-tp7574026.html <http://plone.293351.n2.nabble.com/Error-trying-to-modify-data-with-python-code-in-plone-tp7574026.html>
> To start a new topic under Core Developers, email ml-node+s293351n293355h58-PKuAHvtXa09l57MIdRCFDg@public.gmane.org
> To unsubscribe from Plone, click here <http://plone.293351.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=293351&code=ZXNwZW5AbWVkaWFsb2cubm98MjkzMzUxfC01OTUzNTQ2MjI=>.
> NAML <http://plone.293351.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
View this message in context: http://plone.293351.n2.nabble.com/Error-trying-to-modify-data-with-python-code-in-plone-tp7574026p7574027.html
Sent from the Core Developers mailing list archive at Nabble.com.
------------------------------------------------------------------------------
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