Commit b7054997 authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Arnaud Fontaine

ERP5Catalog.CatalogTool: Do not join with catalog when condition is on uid.

Also, factorise related key string generation.
parent f21e925e
...@@ -249,13 +249,21 @@ class RelatedBaseCategory(Method): ...@@ -249,13 +249,21 @@ class RelatedBaseCategory(Method):
'foreign_side': foreign_side, 'foreign_side': foreign_side,
'query_table_side': query_table_side, 'query_table_side': query_table_side,
} }
self._monotable_template = """\
%%(category_table)s.base_category_uid = %%(base_category_uid)s
%(strict)sAND %%(category_table)s.%(query_table_side)s = %%(query_table)s.uid""" % {
'strict': strict,
'query_table_side': query_table_side,
}
def __call__(self, instance, table_0, table_1, query_table='catalog', def __call__(self, instance, table_0, table_1=None, query_table='catalog',
RELATED_QUERY_SEPARATOR=' AND ', **kw): RELATED_QUERY_SEPARATOR=' AND ', **kw):
"""Create the sql code for this related key.""" """Create the sql code for this related key."""
# Note: in normal conditions, our category's uid will not change from # Note: in normal conditions, our category's uid will not change from
# one invocation to the next. # one invocation to the next.
return self._template % { return (
self._monotable_template if table_1 is None else self._template
) % {
'base_category_uid': instance.getPortalObject().portal_categories.\ 'base_category_uid': instance.getPortalObject().portal_categories.\
_getOb(self._id).getUid(), _getOb(self._id).getUid(),
'query_table': query_table, 'query_table': query_table,
...@@ -869,6 +877,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -869,6 +877,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
base_cat_id_list = self.portal_categories.getBaseCategoryDict() base_cat_id_list = self.portal_categories.getBaseCategoryDict()
default_string = 'default_' default_string = 'default_'
strict_string = 'strict_' strict_string = 'strict_'
related_string = 'related_'
for key in key_list: for key in key_list:
prefix = '' prefix = ''
strict = 0 strict = 0
...@@ -888,22 +897,26 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -888,22 +897,26 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
expected_base_cat_id in base_cat_id_list: expected_base_cat_id in base_cat_id_list:
# We have found a base_category # We have found a base_category
end_key = '_'.join(splitted_key[i:]) end_key = '_'.join(splitted_key[i:])
related = end_key.startswith(related_string)
if end_key.startswith('related_'): if related:
end_key = end_key[len('related_'):] end_key = end_key[len(related_string):]
suffix = '_related'
else:
suffix = ''
# accept only some catalog columns # accept only some catalog columns
if end_key in ('title', 'uid', 'description', 'reference', if end_key in ('title', 'uid', 'description', 'reference',
'relative_url', 'id', 'portal_type', 'relative_url', 'id', 'portal_type',
'simulation_state'): 'simulation_state'):
if strict: is_uid = end_key == 'uid'
pattern = '%s%s | category,catalog/%s/z_related_strict_%s%s' if is_uid:
else: end_key = 'uid' if related else 'category_uid'
pattern = '%s%s | category,catalog/%s/z_related_%s%s' related_key_list.append(
related_key_list.append(pattern % prefix + key + ' | category' +
(prefix, key, end_key, expected_base_cat_id, suffix)) ('' if is_uid else ',catalog') +
'/' +
end_key +
'/z_related_' +
('strict_' if strict else '') +
expected_base_cat_id +
('_related' if related else '')
)
return related_key_list return related_key_list
......
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