Personal tools
You are here: Home Documentation Developers Removing bad kupu resource types.

Removing bad kupu resource types.

by nathanadmin last modified Jul 16, 2010 12:54 PM

how you can remove bad kupu resource types.

At the root of the plone site, create a "Script (Python)" and name it whatever you want.

Then copy this into the body of it:

from Products.CMFCore.utils import getToolByName

request = container.REQUEST
RESPONSE =  request.RESPONSE

kupu = getToolByName(context, 'kupu_library_tool')
types = getToolByName(context, 'portal_types')
all_portal_types = [t.id for t in types.listTypeInfo()]

linkable = list(kupu.getPortalTypesForResourceType('linkable'))
mediaobject = list(kupu.getPortalTypesForResourceType('mediaobject'))
collection = list(kupu.getPortalTypesForResourceType('collection'))
containsanchors = list(kupu.getPortalTypesForResourceType('containsanchors'))

toremove = []
for link in linkable:
    if link.strip() not in all_portal_types:
        toremove.append(link)

print 'remove ', toremove, ' from linkable'
_ = [linkable.remove(link) for link in toremove]    

toremove = []
for link in mediaobject:
    if link.strip() not in all_portal_types:
        toremove.append(link)
    
print 'remove ', toremove, ' from mediaobjecct'
_ = [mediaobject.remove(link) for link in toremove]
    
toremove = []
for link in collection:
    if link.strip() not in all_portal_types:
        toremove.append(link)
    
print 'remove ', toremove, ' from collection'
_ = [collection.remove(link) for link in toremove]
    
toremove = []
for link in containsanchors:
    if link.strip() not in all_portal_types:
        toremove.append(link)
        
print 'remove ', toremove, ' from containsanchors'
_ = [containsanchors.remove(link) for link in toremove]
        
kupu.updateResourceTypes((
    {'resource_type' : 'linkable', 'old_type' : 'linkable', 'portal_types' : linkable },
    {'resource_type' : 'mediaobject', 'old_type' : 'mediaobject', 'portal_types' : mediaobject},
    {'resource_type' : 'collection', 'old_type' : 'collection', 'portal_types' : collection},
    {'resource_type' : 'containsanchors', 'old_type' : 'containsanchors', 'portal_types' : containsanchors},
))

return printed

Then click the "Test" button

That should be it.

Document Actions
  • Print this
  • Bookmarks