Reputation: 5335
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)
Upvotes: 5
Views: 337
Reputation: 3608
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
Upvotes: 1
Reputation: 610
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')
Upvotes: 3
Reputation: 579
You don't need plone.api for this. Thus remove plone.api import and do:
catalog = context.portal_catalog
Upvotes: 6