Commit 2466cf0e authored by Julien Muchembled's avatar Julien Muchembled

Small optimizations in accessor generation

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43570 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cdef4993
......@@ -162,13 +162,15 @@ class PropertySheet(Folder):
portal_type_class.importFromFilesystemDefinition(property_sheet,
category)
constraint_list = getattr(definition_class, '_constraints', None)
if constraint_list:
# Get filesystem Constraint names to be able to map them properly
# to ZODB Constraint Portal Types as some filesystem constraint
# names are 'NAMEConstraint' or 'NAME'
from Products.ERP5Type import Constraint as FilesystemConstraint
filesystem_constraint_class_name_list = [
class_name for class_name in FilesystemConstraint.__dict__ \
if class_name[0] != '_' ]
filesystem_constraint_class_name_set = set(class_name
for class_name in FilesystemConstraint.__dict__
if class_name[0] != '_' )
# Mapping between the filesystem 'type' field and Portal Types ID
portal_type_dict = {}
......@@ -179,21 +181,19 @@ class PropertySheet(Folder):
constraint_class_name = portal_type_id.replace(' ', '')
if constraint_class_name not in filesystem_constraint_class_name_list:
if constraint_class_name not in filesystem_constraint_class_name_set:
constraint_class_name = constraint_class_name.replace('Constraint', '')
if constraint_class_name not in filesystem_constraint_class_name_list:
if constraint_class_name not in filesystem_constraint_class_name_set:
LOG("Tool.PropertySheetTool", WARNING,
"PropertySheet %s: No matching Constraint found for Portal '%s'" % \
(property_sheet_name, portal_type_id))
"PropertySheet %s: No matching Constraint found for Portal %r"
% (property_sheet_name, portal_type_id))
continue
portal_type_dict[constraint_class_name] = portal_type_id
portal_type_dict.update(cls._merged_portal_type_dict)
for constraint in getattr(definition_class, '_constraints', ()):
for constraint in constraint_list:
try:
portal_type = portal_type_dict[constraint['type']]
except KeyError:
......@@ -201,13 +201,10 @@ class PropertySheet(Folder):
# which have not been migrated yet (within BTs or per-project
# Products)) are simply *ignored* for now
LOG("Tool.PropertySheetTool", WARNING,
"Not migrating constraint %s to portal_property_sheets" % \
constraint['type'])
continue
"Not migrating constraint %s to portal_property_sheets"
% constraint['type'])
else:
portal_type_class = types_tool.getPortalTypeClass(portal_type)
# Create the new constraint
portal_type_class.importFromFilesystemDefinition(property_sheet,
constraint)
......
......@@ -65,16 +65,15 @@ def _createAccessorHolderList(site,
"""
Create the accessor holder list with the given ZODB Property Sheets
"""
import erp5.accessor_holder
from erp5 import accessor_holder
property_sheet_tool = site.portal_property_sheets
getPropertySheet = site.portal_property_sheets._getOb
accessor_holder_list = []
if "Base" in property_sheet_name_set:
# useless if Base Category is not yet here or if we're currently
# generating accessors for Base Categories
accessor_holder_class = _generateBaseAccessorHolder(site,
erp5.accessor_holder)
accessor_holder_class = _generateBaseAccessorHolder(site, accessor_holder)
if accessor_holder_class is not None:
accessor_holder_list.append(accessor_holder_class)
......@@ -85,25 +84,22 @@ def _createAccessorHolderList(site,
try:
# Get the already generated accessor holder
accessor_holder_list.append(getattr(erp5.accessor_holder,
property_sheet_name))
accessor_holder_list.append(getattr(accessor_holder, property_sheet_name))
except AttributeError:
# Generate the accessor holder as it has not been done yet
try:
property_sheet = getattr(property_sheet_tool, property_sheet_name)
property_sheet = getPropertySheet(property_sheet_name)
accessor_holder_class = property_sheet.createAccessorHolder()
except Exception:
LOG("ERP5Type.dynamic", ERROR,
"Ignoring missing or Invalid Property Sheet " + property_sheet_name)
raise
accessor_holder_list.append(accessor_holder_class)
setattr(erp5.accessor_holder, property_sheet_name,
accessor_holder_class)
setattr(accessor_holder, property_sheet_name, accessor_holder_class)
# LOG("ERP5Type.dynamic", INFO,
# "Created accessor holder for %s" % property_sheet_name)
......@@ -113,7 +109,7 @@ def _createAccessorHolderList(site,
accessor_holder_class = \
_generatePreferenceToolAccessorHolder(site,
accessor_holder_list,
erp5.accessor_holder)
accessor_holder)
accessor_holder_list.insert(0, accessor_holder_class)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment