Skip to main content

Custom Fields in Smart Folders Cont.

May 21, 2008

You can still specify index fields in content types if you like, but you do not have to.  I'm just going to throw the code up.  It should be easy enough to understand.  Figuring out how to do it was the difficult part.  This registers everything with your smart folders so you can grab these fields and sort on them.

 

def install_indexes(self):
    ct = getToolByName(self, 'portal_catalog')
    atct = getToolByName(self, 'portal_atct')

    for index in get_indexes():
        if index['name'] not in ct.indexes():
            ct.addIndex(index['name'], 'FieldIndex')
           
        atct.updateIndex(index['name'], index['friendlyName'], index['description'], True)
    
    for entry in get_indexes():
        if entry['name'] not in ct.schema():
            ct.addColumn(entry['name'])
        
        atct.updateMetadata(entry['name'], entry['friendlyName'], entry['description'], True)