Commit 0eee3ba1 authored by Vincent Pelletier's avatar Vincent Pelletier

Revert commit 25752 to change implementation of ScriptableKeys. Add a test.

  A "ScriptableKey" configuration is not a SearchKey, strictly speaking: a
  SearchKey generates Query instances from a value (the SearchKey contains the
  column information), and ScriptableKey's "script" does exactly that. So
  there is no need for any SearchKey to generate those Queries, so it's better
  to fix the feature at getColumnDefaultSearchKey caller's level.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25773 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c2c5607a
......@@ -1861,22 +1861,19 @@ class Catalog(Folder,
- If returned SearchKey is a RelatedKey, value is its definition
- Otherwise, value is None
"""
# Is key a "real" column or some related key or scriptable key?
# Is key a "real" column or some related key ?
related_key_definition = None
if key in self.getColumnMap():
search_key = self.getSearchKey(key, search_key_name)
else:
# Maybe a related key...
related_key_definition = self.getRelatedKeyDefinition(key)
if related_key_definition is not None:
# It's a related key
search_key = self.getSearchKey(key, 'RelatedKey')
elif self.getScriptableKeyScript(key) is not None:
# It's a scriptable key
search_key = self.getSearchKey(key, 'RawKey')
else:
if related_key_definition is None:
# Unknown
search_key = None
else:
# It's a related key
search_key = self.getSearchKey(key, 'RelatedKey')
return search_key, related_key_definition
@profiler_decorator
......@@ -1998,9 +1995,12 @@ class Catalog(Folder,
implicit_table_list.append(key)
LOG('buildQuery', WARNING, 'Discarding empty value for key %r: %r' % (key, value))
else:
script = self.getScriptableKeyScript(key)
if isinstance(value, _Query):
# Query instance: use as such, ignore key.
result = value
elif script is not None:
result = script(value)
elif isinstance(value, basestring):
# String: parse using key's default search key.
search_key = self.getColumnDefaultSearchKey(key)
......
......@@ -116,6 +116,7 @@ class DummyCatalog(SQLCatalog):
sql_catalog_keyword_search_keys = ('keyword', )
sql_catalog_datetime_search_keys = ('date', )
sql_catalog_scriptable_keys = ('scriptable_keyword | scriptableKeyScript', )
def getColumnMap(self):
return {
......@@ -141,6 +142,9 @@ class DummyCatalog(SQLCatalog):
assert len(kw) == 4
return '%(table_0)s.uid = %(query_table)s.uid AND %(table_0)s.other_uid = %(table_1)s' % kw
def scriptableKeyScript(self, value):
return SimpleQuery(operator='=', keyword=value)
class TestSQLCatalog(unittest.TestCase):
def setUp(self):
self._catalog = DummyCatalog('dummy_catalog')
......@@ -285,6 +289,10 @@ class TestSQLCatalog(unittest.TestCase):
, operator='and'), operator='and'),
{'query': ComplexQuery(Query(related_default='a'), Query(related_default='b'))})
def test_007_testScriptableKey(self):
self.catalog(ReferenceQuery(ReferenceQuery(operator='=', keyword='%a%'), operator='and'),
{'scriptable_keyword': '%a%'})
##return catalog(title=Query(title='a', operator='not'))
#return catalog(title={'query': 'a', 'operator': 'not'})
#return catalog(title={'query': ['a', 'b'], 'operator': 'not'})
......
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