Commit 7c638a4f authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Catalog.CatalogTool: Truncate string instead of preparing offsets.

Simplifies extension.
Also, factorise constants a bit.
parent 9572fc1f
...@@ -57,8 +57,8 @@ from zLOG import LOG, PROBLEM, WARNING, INFO ...@@ -57,8 +57,8 @@ from zLOG import LOG, PROBLEM, WARNING, INFO
ACQUIRE_PERMISSION_VALUE = [] ACQUIRE_PERMISSION_VALUE = []
DYNAMIC_METHOD_NAME = 'z_related_' DYNAMIC_METHOD_NAME = 'z_related_'
DYNAMIC_METHOD_NAME_LEN = len(DYNAMIC_METHOD_NAME) DYNAMIC_METHOD_NAME_LEN = len(DYNAMIC_METHOD_NAME)
STRICT_DYNAMIC_METHOD_NAME = DYNAMIC_METHOD_NAME + 'strict_' STRICT_METHOD_NAME = 'strict_'
STRICT_DYNAMIC_METHOD_NAME_LEN = len(STRICT_DYNAMIC_METHOD_NAME) STRICT_METHOD_NAME_LEN = len(STRICT_METHOD_NAME)
RELATED_DYNAMIC_METHOD_NAME = '_related' RELATED_DYNAMIC_METHOD_NAME = '_related'
# Negative as it's used as a slice end offset # Negative as it's used as a slice end offset
RELATED_DYNAMIC_METHOD_NAME_LEN = -len(RELATED_DYNAMIC_METHOD_NAME) RELATED_DYNAMIC_METHOD_NAME_LEN = -len(RELATED_DYNAMIC_METHOD_NAME)
...@@ -941,7 +941,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -941,7 +941,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
) )
base_cat_id_set.discard('parent') base_cat_id_set.discard('parent')
default_string = 'default_' default_string = 'default_'
strict_string = 'strict_' strict_string = STRICT_METHOD_NAME
related_string = 'related_' related_string = 'related_'
column_map = self.getSQLCatalog(sql_catalog_id).getColumnMap() column_map = self.getSQLCatalog(sql_catalog_id).getColumnMap()
for key in key_list: for key in key_list:
...@@ -953,7 +953,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -953,7 +953,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
if key.startswith(strict_string): if key.startswith(strict_string):
strict = 1 strict = 1
key = key[len(strict_string):] key = key[len(strict_string):]
prefix = prefix + strict_string prefix += strict_string
split_key = key.split('_') split_key = key.split('_')
for i in xrange(len(split_key) - 1, 0, -1): for i in xrange(len(split_key) - 1, 0, -1):
expected_base_cat_id = '_'.join(split_key[0:i]) expected_base_cat_id = '_'.join(split_key[0:i])
...@@ -975,10 +975,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -975,10 +975,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
('' if is_uid else ',catalog') + ('' if is_uid else ',catalog') +
'/' + '/' +
end_key + end_key +
'/z_related_' + '/' + DYNAMIC_METHOD_NAME +
('strict_' if strict else '') + (STRICT_METHOD_NAME if strict else '') +
expected_base_cat_id + expected_base_cat_id +
('_related' if related else '') (RELATED_DYNAMIC_METHOD_NAME if related else '')
) )
return related_key_list return related_key_list
...@@ -991,18 +991,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -991,18 +991,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
result = None result = None
if name.startswith(DYNAMIC_METHOD_NAME) and \ if name.startswith(DYNAMIC_METHOD_NAME) and \
not name.endswith(ZOPE_SECURITY_SUFFIX): not name.endswith(ZOPE_SECURITY_SUFFIX):
base_name = name[DYNAMIC_METHOD_NAME_LEN:]
kw = {} kw = {}
if name.endswith(RELATED_DYNAMIC_METHOD_NAME): if base_name.endswith(RELATED_DYNAMIC_METHOD_NAME):
end_offset = RELATED_DYNAMIC_METHOD_NAME_LEN base_name = base_name[:RELATED_DYNAMIC_METHOD_NAME_LEN]
kw['related'] = 1 kw['related'] = 1
else: if base_name.startswith(STRICT_METHOD_NAME):
end_offset = None base_name = base_name[STRICT_METHOD_NAME_LEN:]
if name.startswith(STRICT_DYNAMIC_METHOD_NAME):
start_offset = STRICT_DYNAMIC_METHOD_NAME_LEN
kw['strict_membership'] = 1 kw['strict_membership'] = 1
else: method = RelatedBaseCategory(base_name, **kw)
start_offset = DYNAMIC_METHOD_NAME_LEN
method = RelatedBaseCategory(name[start_offset:end_offset], **kw)
setattr(self.__class__, name, method) setattr(self.__class__, name, method)
# This getattr has 2 purposes: # This getattr has 2 purposes:
# - wrap in acquisition context # - wrap in acquisition context
......
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