Several bugfixes while handling abstract classes (appy.gen) and added a first code chunk used while installing a gen-application for Plone 3.

This commit is contained in:
Gaetan Delannay 2010-04-26 18:19:34 +02:00
parent ca7b688c00
commit 46cda3f755
7 changed files with 49 additions and 3 deletions

View file

@ -1,3 +1,6 @@
0.5.5 (2010-04-21)
- Lots of minor improvements and implementation of first elements for a Plone3 generator.
0.5.4 (2010-03-24)
- Improved gen search screens and many more minor bugfixes and features.

View file

@ -237,6 +237,7 @@ class PloneInstaller:
# Creates the new-way templates for Pod fields if they do not exist.
for contentType, attrNames in self.attributes.iteritems():
appyClass = self.tool.getAppyClass(contentType)
if not appyClass: continue # May be an abstract class
for attrName in attrNames:
appyType = getattr(appyClass, attrName)
if appyType.type == 'Pod':

View file

@ -261,7 +261,7 @@ class FlavourMixin(AbstractMixin):
being effectively used in the search screen.'''
res = []
appyClass = self.getAppyClass(contentType)
for attrName in getattr(self, 'searchFieldsFor%s' % contentType):
for attrName in getattr(self, 'searchFieldsFor%s' % contentType, ()):
attr = getattr(appyClass, attrName)
dAttr = self._appy_getTypeAsDict(attrName, attr, appyClass)
res.append((attrName, dAttr))

View file

@ -333,6 +333,7 @@ class ToolMixin(AbstractMixin):
'''Gets the Appy Python class that is related to p_contentType.'''
# Retrieve first the Archetypes class corresponding to p_ContentType
portalType = self.portal_types.get(contentType)
if not portalType: return None
atClassName = portalType.getProperty('content_meta_type')
appName = self.getProductConfig().PROJECTNAME
exec 'from Products.%s.%s import %s as atClass' % \

View file

@ -261,7 +261,10 @@ class AbstractMixin:
return t('%s_%s_list_%s' % (self.meta_type, name, v))
if not isinstance(v, basestring):
# Archetypes "Description" fields may hold a BaseUnit instance.
v = unicode(v)
try:
v = unicode(v)
except UnicodeDecodeError:
v = str(v)
return v
elif vType == 'Boolean':
if v: return self.translate('yes', domain='plone')

0
gen/plone3/__init__.py Normal file
View file

38
gen/plone3/installer.py Normal file
View file

@ -0,0 +1,38 @@
'''This package contains stuff used at run-time for installing a generated
Plone product.'''
# ------------------------------------------------------------------------------
from appy.gen.plone25.installer import PloneInstaller as Plone25Installer
class ZCTextIndexInfo:
'''Silly class used for storing information about a ZCTextIndex.'''
lexicon_id = "plone_lexicon"
index_type = 'Okapi BM25 Rank'
class PloneInstaller(Plone25Installer):
'''This Plone installer runs every time the generated Plone product is
installed or uninstalled (in the Plone configuration interface).'''
@staticmethod
def updateIndexes(ploneSite, indexInfo, logger):
'''This method creates or updates, in a p_ploneSite, definitions of
indexes in its portal_catalog, based on index-related information
given in p_indexInfo. p_indexInfo is a dictionary of the form
{s_indexName:s_indexType}. Here are some examples of index types:
"FieldIndex", "ZCTextIndex", "DateIndex".'''
catalog = ploneSite.portal_catalog
indexNames = catalog.indexes()
for indexName, indexType in indexInfo.iteritems():
if indexName not in indexNames:
# We need to create this index
if indexType != 'ZCTextIndex':
catalog.addIndex(indexName, indexType)
else:
catalog.addIndex(indexName,indexType,extra=ZCTextIndexInfo)
logger.info('Creating index "%s" of type "%s"...' % \
(indexName, indexType))
# Indexing database content based on this index.
catalog.reindexIndex(indexName, ploneSite.REQUEST)
logger.info('Done.')
# TODO: if the index already exists but has not the same type, we
# re-create it with the same type and we reindex it.
# ------------------------------------------------------------------------------