Commit 772033ed authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Catalog.CatalogTool: Add "parent" support to dynamic related keys.

Allows accessing any catalog column after parent relation, instead of only
pre-configured columns.
Allows reverse relation lookup (for the non-parent part of the relation,
as child relationship is not supported).
Also, drop now-redundant related keys.
parent 7c638a4f
<dtml-var table_1>.uid = <dtml-var table_0>.category_uid
AND <dtml-var table_0>.base_category_uid = <dtml-var "portal_categories.base_contribution.getUid()">
AND <dtml-var table_0>.uid = catalog.parent_uid
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>table_0\r\n
table_1</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>z_related_parent_base_contribution</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<key_list>
<key>parent_base_contribution_uid | category,catalog/uid/z_related_parent_base_contribution</key>
</key_list>
\ No newline at end of file
erp5_mysql_innodb/z_related_parent_base_contribution
\ No newline at end of file
parent_base_contribution_uid | category,catalog/uid/z_related_parent_base_contribution
\ No newline at end of file
<dtml-var table_0>.base_category_uid = <dtml-var "portal_categories.specialise.getUid()">
AND <dtml-var table_1>.uid = <dtml-var table_0>.category_uid
<dtml-var RELATED_QUERY_SEPARATOR>
<dtml-var table_0>.uid = <dtml-var query_table>.parent_uid
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>table_0\r\n
table_1\r\n
RELATED_QUERY_SEPARATOR=" AND "\r\n
query_table="catalog"</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>z_related_parent_specialise</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<dtml-var table_1>.uid = <dtml-var table_0>.category_uid
<dtml-var RELATED_QUERY_SEPARATOR> <dtml-var table_0>.base_category_uid = <dtml-var "portal_categories.group.getUid()">
AND <dtml-var table_0>.uid = <dtml-var query_table>.parent_uid
AND <dtml-var table_0>.category_strict_membership = 1
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL" module="Products.ZSQLMethods.SQL"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>query_table\r\n
table_0\r\n
table_1\r\n
RELATED_QUERY_SEPARATOR=" AND "</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>connection_hook</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>z_related_parent_strict_group</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
<key>parent_portal_type | catalog/portal_type/z_related_parent</key> <key>parent_portal_type | catalog/portal_type/z_related_parent</key>
<key>parent_reference | catalog/reference/z_related_parent</key> <key>parent_reference | catalog/reference/z_related_parent</key>
<key>parent_relative_url | catalog/relative_url/z_related_parent</key> <key>parent_relative_url | catalog/relative_url/z_related_parent</key>
<key>parent_specialise_portal_type | category,catalog/portal_type/z_related_parent_specialise</key>
<key>parent_specialise_reference | category,catalog/reference/z_related_parent_specialise</key>
<key>parent_strict_group_uid | category,catalog/uid/z_related_parent_strict_group</key>
<key>parent_string_index | catalog/string_index/z_related_parent</key> <key>parent_string_index | catalog/string_index/z_related_parent</key>
<key>parent_title | catalog/title/z_related_parent</key> <key>parent_title | catalog/title/z_related_parent</key>
<key>predicate_category_base_category_uid | predicate_category/base_category_uid/z_related_predicate_category</key> <key>predicate_category_base_category_uid | predicate_category/base_category_uid/z_related_predicate_category</key>
......
...@@ -93,8 +93,6 @@ erp5_mysql_innodb/z_related_mirror_section_uid_from_stock ...@@ -93,8 +93,6 @@ erp5_mysql_innodb/z_related_mirror_section_uid_from_stock
erp5_mysql_innodb/z_related_node_uid_from_item erp5_mysql_innodb/z_related_node_uid_from_item
erp5_mysql_innodb/z_related_node_uid_from_stock erp5_mysql_innodb/z_related_node_uid_from_stock
erp5_mysql_innodb/z_related_parent erp5_mysql_innodb/z_related_parent
erp5_mysql_innodb/z_related_parent_specialise
erp5_mysql_innodb/z_related_parent_strict_group
erp5_mysql_innodb/z_related_payment_request_uid_from_stock erp5_mysql_innodb/z_related_payment_request_uid_from_stock
erp5_mysql_innodb/z_related_payment_uid_from_stock erp5_mysql_innodb/z_related_payment_uid_from_stock
erp5_mysql_innodb/z_related_predicate erp5_mysql_innodb/z_related_predicate
......
...@@ -38,7 +38,6 @@ stock_project_category_strict_membership_uid | category/category_uid/z_related_s ...@@ -38,7 +38,6 @@ stock_project_category_strict_membership_uid | category/category_uid/z_related_s
stock_project_category_uid | category/category_uid/z_related_project_uid_from_stock stock_project_category_uid | category/category_uid/z_related_project_uid_from_stock
deliveryLineType | stock,catalog/portal_type/z_related_uid_or_parent_uid deliveryLineType | stock,catalog/portal_type/z_related_uid_or_parent_uid
item_section_category_uid | category/category_uid/z_related_section_uid_from_item item_section_category_uid | category/category_uid/z_related_section_uid_from_item
parent_specialise_portal_type | category,catalog/portal_type/z_related_parent_specialise
parent_relative_url | catalog/relative_url/z_related_parent parent_relative_url | catalog/relative_url/z_related_parent
resourceType | catalog/portal_type/z_related_resource_uid_from_stock resourceType | catalog/portal_type/z_related_resource_uid_from_stock
grand_parent_portal_type | catalog,catalog/portal_type/z_related_grand_parent grand_parent_portal_type | catalog,catalog/portal_type/z_related_grand_parent
...@@ -55,8 +54,6 @@ parent_portal_type | catalog/portal_type/z_related_parent ...@@ -55,8 +54,6 @@ parent_portal_type | catalog/portal_type/z_related_parent
translated_causality_state | translation/translated_message/z_related_translated_causality_state translated_causality_state | translation/translated_message/z_related_translated_causality_state
translated_causality_state_title | translation/translated_message/z_related_translated_causality_state_title translated_causality_state_title | translation/translated_message/z_related_translated_causality_state_title
metric_type_uid | measure/metric_type_uid/z_related_metric_type metric_type_uid | measure/metric_type_uid/z_related_metric_type
parent_strict_group_uid | category,catalog/uid/z_related_parent_strict_group
parent_specialise_reference | category,catalog/reference/z_related_parent_specialise
predicate_category_base_category_uid | predicate_category/base_category_uid/z_related_predicate_category predicate_category_base_category_uid | predicate_category/base_category_uid/z_related_predicate_category
predicate_category_category_strict_membership | predicate_category/category_strict_membership/z_related_predicate_category predicate_category_category_strict_membership | predicate_category/category_strict_membership/z_related_predicate_category
predicate_category_category_uid | predicate_category/category_uid/z_related_predicate_category predicate_category_category_uid | predicate_category/category_uid/z_related_predicate_category
......
...@@ -59,6 +59,8 @@ DYNAMIC_METHOD_NAME = 'z_related_' ...@@ -59,6 +59,8 @@ DYNAMIC_METHOD_NAME = 'z_related_'
DYNAMIC_METHOD_NAME_LEN = len(DYNAMIC_METHOD_NAME) DYNAMIC_METHOD_NAME_LEN = len(DYNAMIC_METHOD_NAME)
STRICT_METHOD_NAME = 'strict_' STRICT_METHOD_NAME = 'strict_'
STRICT_METHOD_NAME_LEN = len(STRICT_METHOD_NAME) STRICT_METHOD_NAME_LEN = len(STRICT_METHOD_NAME)
PARENT_METHOD_NAME = 'parent_'
PARENT_METHOD_NAME_LEN = len(PARENT_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)
...@@ -251,7 +253,7 @@ class IndexableObjectWrapper(object): ...@@ -251,7 +253,7 @@ class IndexableObjectWrapper(object):
class RelatedBaseCategory(Method): class RelatedBaseCategory(Method):
"""A Dynamic Method to act as a related key. """A Dynamic Method to act as a related key.
""" """
def __init__(self, id, strict_membership=0, related=0): def __init__(self, id, strict_membership=0, related=0, query_table_column='uid'):
self._id = id self._id = id
if strict_membership: if strict_membership:
strict = 'AND %(category_table)s.category_strict_membership = 1\n' strict = 'AND %(category_table)s.category_strict_membership = 1\n'
...@@ -274,16 +276,18 @@ class RelatedBaseCategory(Method): ...@@ -274,16 +276,18 @@ class RelatedBaseCategory(Method):
%%(category_table)s.base_category_uid = %%(base_category_uid)s %%(category_table)s.base_category_uid = %%(base_category_uid)s
%(strict)sAND %%(foreign_catalog)s.uid = %%(category_table)s.%(foreign_side)s %(strict)sAND %%(foreign_catalog)s.uid = %%(category_table)s.%(foreign_side)s
%%(RELATED_QUERY_SEPARATOR)s %%(RELATED_QUERY_SEPARATOR)s
%%(category_table)s.%(query_table_side)s = %%(query_table)s.uid""" % { %%(category_table)s.%(query_table_side)s = %%(query_table)s.%(query_table_column)s""" % {
'strict': strict, 'strict': strict,
'foreign_side': foreign_side, 'foreign_side': foreign_side,
'query_table_side': query_table_side, 'query_table_side': query_table_side,
'query_table_column': query_table_column
} }
self._monotable_template = """\ self._monotable_template = """\
%%(category_table)s.base_category_uid = %%(base_category_uid)s %%(category_table)s.base_category_uid = %%(base_category_uid)s
%(strict)sAND %%(category_table)s.%(query_table_side)s = %%(query_table)s.uid""" % { %(strict)sAND %%(category_table)s.%(query_table_side)s = %%(query_table)s.%(query_table_column)s""" % {
'strict': strict, 'strict': strict,
'query_table_side': query_table_side, 'query_table_side': query_table_side,
'query_table_column': query_table_column,
} }
def __call__(self, instance, table_0, table_1=None, query_table='catalog', def __call__(self, instance, table_0, table_1=None, query_table='catalog',
...@@ -942,11 +946,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -942,11 +946,13 @@ 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_METHOD_NAME strict_string = STRICT_METHOD_NAME
parent_string = PARENT_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:
prefix = '' prefix = ''
strict = 0 strict = 0
parent = 0
if key.startswith(default_string): if key.startswith(default_string):
key = key[len(default_string):] key = key[len(default_string):]
prefix = default_string prefix = default_string
...@@ -954,6 +960,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -954,6 +960,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
strict = 1 strict = 1
key = key[len(strict_string):] key = key[len(strict_string):]
prefix += strict_string prefix += strict_string
if key.startswith(parent_string):
parent = 1
key = key[len(parent_string):]
prefix += parent_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])
...@@ -977,6 +987,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -977,6 +987,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
end_key + end_key +
'/' + DYNAMIC_METHOD_NAME + '/' + DYNAMIC_METHOD_NAME +
(STRICT_METHOD_NAME if strict else '') + (STRICT_METHOD_NAME if strict else '') +
(PARENT_METHOD_NAME if parent else '') +
expected_base_cat_id + expected_base_cat_id +
(RELATED_DYNAMIC_METHOD_NAME if related else '') (RELATED_DYNAMIC_METHOD_NAME if related else '')
) )
...@@ -999,6 +1010,9 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -999,6 +1010,9 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
if base_name.startswith(STRICT_METHOD_NAME): if base_name.startswith(STRICT_METHOD_NAME):
base_name = base_name[STRICT_METHOD_NAME_LEN:] base_name = base_name[STRICT_METHOD_NAME_LEN:]
kw['strict_membership'] = 1 kw['strict_membership'] = 1
if base_name.startswith(PARENT_METHOD_NAME):
base_name = base_name[PARENT_METHOD_NAME_LEN:]
kw['query_table_column'] = 'parent_uid'
method = RelatedBaseCategory(base_name, **kw) method = RelatedBaseCategory(base_name, **kw)
setattr(self.__class__, name, method) setattr(self.__class__, name, method)
# This getattr has 2 purposes: # This getattr has 2 purposes:
......
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