[gen] Cleaner and more robust approach when using Zope database indexes.

This commit is contained in:
Gaetan Delannay 2012-09-04 18:00:22 +02:00
parent 5c2d94236f
commit c2eaab4b44
6 changed files with 75 additions and 30 deletions

View file

@ -4,7 +4,8 @@
# ------------------------------------------------------------------------------
import os, os.path, mimetypes
import appy.pod
from appy.gen import Type, Search, Ref, String, WorkflowAnonymous
from appy.gen import Type, Search, Ref, String, WorkflowAnonymous, \
defaultIndexes
from appy.gen.utils import createObject
from appy.shared.utils import getOsTempFolder, executeCommand, \
normalizeString, sequenceTypes
@ -59,6 +60,24 @@ class AbstractWrapper(object):
if not res: res = cfg.defaultAddRoles
return res
@classmethod
def getIndexes(klass, includeDefaults=True):
'''Returns a dict whose keys are the names of the indexes that are
applicable to instances of this class, and whose values are the
(Zope) types of those indexes.'''
# Start with the standard indexes applicable for any Appy class.
if includeDefaults:
res = defaultIndexes.copy()
else:
res = {}
# Add the indexed fields found on this class
for field in klass.__fields__:
if not field.indexed or (field.name == 'title'): continue
n = field.name
indexName = 'get%s%s' % (n[0].upper(), n[1:])
res[indexName] = field.getIndexType()
return res
# --------------------------------------------------------------------------
# Instance methods
# --------------------------------------------------------------------------