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