Back to index

plone3  3.1.7
setuphandlers.py
Go to the documentation of this file.
00001 """
00002 Archetypes setup handlers.
00003 """
00004 
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.Archetypes.config import TOOL_NAME, REFERENCE_CATALOG, UID_CATALOG
00007 
00008 def install_uidcatalog(out, site, rebuild=False):
00009     catalog = getToolByName(site, UID_CATALOG)
00010 
00011     index_defs= (('UID', 'FieldIndex'),
00012                  ('Type', 'FieldIndex'),
00013                  ('id', 'FieldIndex'),
00014                  ('Title', 'FieldIndex'), # used for sorting
00015                  ('portal_type', 'FieldIndex'),)
00016     metadata_defs = ('UID', 'Type', 'id', 'Title', 'portal_type', 'meta_type')
00017     reindex = False
00018 
00019     for indexName, indexType in index_defs:
00020         if indexName not in catalog.indexes():
00021             catalog.addIndex(indexName, indexType, extra=None)
00022             reindex = True
00023 
00024     for metadata in metadata_defs:
00025         if not indexName in catalog.schema():
00026             catalog.addColumn(metadata)
00027             reindex = True
00028     if reindex:
00029         catalog.manage_reindexIndex()
00030 
00031 
00032 def install_referenceCatalog(out, site, rebuild=False):
00033     catalog = getToolByName(site, REFERENCE_CATALOG)
00034     reindex = False
00035 
00036     for indexName, indexType in (('UID', 'FieldIndex'),
00037                                  ('sourceUID', 'FieldIndex'),
00038                                  ('targetUID', 'FieldIndex'),
00039                                  ('relationship', 'FieldIndex'),
00040                                  ('targetId', 'FieldIndex'),):
00041         if not indexName in catalog.indexes():
00042             catalog.addIndex(indexName, indexType, extra=None)
00043             reindex = True
00044         if not indexName in catalog.schema():
00045             catalog.addColumn(indexName)
00046             reindex = True
00047     if reindex:
00048         catalog.manage_reindexIndex()
00049 
00050 
00051 def install_templates(out, site):
00052     at = getToolByName(site, TOOL_NAME)
00053     at.registerTemplate('base_view', 'Base View')
00054 
00055 
00056 def setupArchetypes(context):
00057     """
00058     Setup Archetypes step.
00059     """
00060     # Only run step if a flag file is present (e.g. not an extension profile)
00061     if context.readDataFile('archetypes-various.txt') is None:
00062         return
00063     out = []
00064     site = context.getSite()
00065     install_uidcatalog(out, site)
00066     install_referenceCatalog(out, site)
00067     install_templates(out, site)