I have this python script designed to rebuild the catalog for a particular content type, however when I visit it's url in the browser I get 'insufficient privileges' even when logged in as admin. How can I run something like this?
import plone.api
catalog = plone.api.portal.get_tool(name='portal_catalog') for brain in catalog(portal_type='Resource'):
obj = brain.getObject()
catalog.catalog_object(obj)
You don't need plone.api for this. Thus remove plone.api import and do:
catalog = context.portal_catalog
ScriptPython is restricted Python, that means that you can not import every Python module you want. That could the reason that you can't use plone.api in ScriptPython. But you can import getToolByName in that Script and get tools like the portal_catalog with it.
from Products.CMFCore.utils import getToolByName
catalog = getToolByName('portal_catalog')
If create your script in filesystem, you ca run.
bin/instace run your_script
But in your case, you don't need import plone.api
Plone in ZMI have many restrictions for import something.
See more informations about portal_catalog in official plone site Documentation Query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With