Commit 7a221299 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add sql_catalog_search_keys, that makes it possible to customise Column - SearchKey mappings.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37941 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0e8df2b9
......@@ -3540,22 +3540,26 @@ class RoleTemplateItem(BaseTemplateItem):
path = obsolete_key
bta.addObject(obj=xml_data, name=path)
class CatalogResultKeyTemplateItem(BaseTemplateItem):
class CatalogSearchKeyTemplateItem(BaseTemplateItem):
key_list_attr = 'sql_catalog_search_keys'
key_list_title = 'search_key_list'
key_title = 'Search key'
def build(self, context, **kw):
import ipdb; ipdb.set_trace()
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_result_keys = list(catalog.sql_search_result_keys)
catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
key_list = []
for key in self._archive.keys():
if key in sql_search_result_keys:
if key in catalog_key_list:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Result key "%r" not found in catalog' %(key,)
raise NotFound, '%s %r not found in catalog' %(self.key_title, key)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'result_key_list'] = key_list
self._objects['%s/%s' % (self.__class__.__name__, self.key_list_title)] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
......@@ -3571,7 +3575,7 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_result_keys = list(catalog.sql_search_result_keys)
catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
......@@ -3583,31 +3587,31 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related key
if update_dict.has_key('result_key_list') or force:
if update_dict.has_key(self.key_list_title) or force:
if not force:
action = update_dict['result_key_list']
action = update_dict[self.key_list_title]
if action == 'nothing':
return
for key in keys:
if key not in sql_search_result_keys:
sql_search_result_keys.append(key)
catalog.sql_search_result_keys = sql_search_result_keys
if key not in catalog_key_list:
catalog_key_list.append(key)
setattr(catalog, self.key_list_attr, catalog_key_list)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_result_keys = list(catalog.sql_search_result_keys)
catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_search_result_keys:
sql_search_result_keys.remove(key)
catalog.sql_search_result_keys = sql_search_result_keys
if key in catalog_key_list:
catalog_key_list.remove(key)
setattr(catalog, self.key_list_attr, catalog_key_list)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
......@@ -3629,38 +3633,24 @@ class CatalogResultKeyTemplateItem(BaseTemplateItem):
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
class CatalogResultKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_search_result_keys'
key_list_title = 'result_key_list'
key_title = 'Result key'
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_related_keys = list(catalog.sql_catalog_related_keys)
key_list = []
for key in self._archive.keys():
if key in sql_search_related_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Related key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'related_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
class CatalogRelatedKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_related_keys'
key_list_title = 'related_key_list'
key_title = 'Related key'
# override this method to support 'key_list' for backward compatibility.
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_related_keys = list(catalog.sql_catalog_related_keys)
catalog_key_list = list(getattr(catalog, self.key_list_attr, []))
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
......@@ -3672,955 +3662,74 @@ class CatalogRelatedKeyTemplateItem(BaseTemplateItem):
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage related key
if update_dict.has_key('related_key_list') or update_dict.has_key('key_list') or force:
if update_dict.has_key(self.key_list_title) or update_dict.has_key('key_list') or force:
if not force:
if update_dict.has_key('related_key_list'):
action = update_dict['related_key_list']
if update_dict.has_key(self.key_list_title):
action = update_dict[self.key_list_title]
else: # XXX for backward compatibility
action = update_dict['key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_related_keys:
sql_catalog_related_keys.append(key)
catalog.sql_catalog_related_keys = tuple(sql_catalog_related_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_related_keys = list(catalog.sql_catalog_related_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_related_keys:
sql_catalog_related_keys.remove(key)
catalog.sql_catalog_related_keys = sql_catalog_related_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogResultTableTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_result_tables = list(catalog.sql_search_tables)
key_list = []
for key in self._archive.keys():
if key in sql_search_result_tables:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Result table "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'result_table_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_tables = list(catalog.sql_search_tables)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related keys
if update_dict.has_key('result_table_list') or force:
if not force:
action = update_dict['result_table_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_search_tables:
sql_search_tables.append(key)
catalog.sql_search_tables = tuple(sql_search_tables)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_search_tables = list(catalog.sql_search_tables)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_search_tables:
sql_search_tables.remove(key)
catalog.sql_search_tables = sql_search_tables
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
if key not in catalog_key_list:
catalog_key_list.append(key)
setattr(catalog, self.key_list_attr, catalog_key_list)
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogResultTableTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_search_tables'
key_list_title = 'result_table_list'
key_title = 'Result table'
# keyword
class CatalogKeywordKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_keyword_keys = list(catalog.sql_catalog_keyword_search_keys)
key_list = []
for key in self._archive.keys():
if key in sql_keyword_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Keyword key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'keyword_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_keyword_keys = list(catalog.sql_catalog_keyword_search_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related key
if update_dict.has_key('keyword_key_list') or force:
if not force:
action = update_dict['keyword_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_keyword_keys:
sql_keyword_keys.append(key)
catalog.sql_catalog_keyword_search_keys = sql_keyword_keys
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_keyword_keys = list(catalog.sql_catalog_keyword_search_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_keyword_keys:
sql_keyword_keys.remove(key)
catalog.sql_catalog_keyword_search_keys = sql_keyword_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogKeywordKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_keyword_search_keys'
key_list_title = 'keyword_key_list'
key_title = 'Keyword key'
# datetime
class CatalogDateTimeKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_datetime_keys = list(getattr(catalog, 'sql_catalog_datetime_search_keys', []))
key_list = []
for key in self._archive.keys():
if key in sql_datetime_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'DateTime key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'datetime_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(context)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
class CatalogDateTimeKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_datetime_search_keys'
key_list_title = 'datetime_key_list'
key_title = 'DateTime key'
sql_datetime_keys = list(getattr(catalog, 'sql_catalog_datetime_search_keys', []))
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related key
if update_dict.has_key('datetime_key_list') or force:
if not force:
action = update_dict['datetime_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_datetime_keys:
sql_datetime_keys.append(key)
catalog.sql_catalog_datetime_search_keys = sql_datetime_keys
# full text
class CatalogFullTextKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_full_text_search_keys'
key_list_title = 'full_text_key_list'
key_title = 'Fulltext key'
def uninstall(self, context, **kw):
catalog = _getCatalogValue(context)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available - uninstall')
return
sql_datetime_keys = list(getattr(catalog, 'sql_catalog_datetime_search_keys', []))
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_datetime_keys:
sql_datetime_keys.remove(key)
catalog.sql_catalog_datetime_search_keys = sql_datetime_keys
BaseTemplateItem.uninstall(self, context, **kw)
# request
class CatalogRequestKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_request_keys'
key_list_title = 'request_key_list'
key_title = 'Request key'
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
# full text
class CatalogFullTextKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_full_text_keys = list(catalog.sql_catalog_full_text_search_keys)
key_list = []
for key in self._archive.keys():
if key in sql_full_text_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Fulltext key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'full_text_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_full_text_keys = list(catalog.sql_catalog_full_text_search_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related key
if update_dict.has_key('full_text_key_list') or force:
if not force:
action = update_dict['full_text_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_full_text_keys:
sql_full_text_keys.append(key)
catalog.sql_catalog_full_text_search_keys = sql_full_text_keys
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_full_text_keys = list(catalog.sql_catalog_full_text_search_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_full_text_keys:
sql_full_text_keys.remove(key)
catalog.sql_catalog_full_text_search_keys = sql_full_text_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
# request
class CatalogRequestKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_request_keys = list(catalog.sql_catalog_request_keys)
key_list = []
for key in self._archive.keys():
if key in sql_request_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Request key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'request_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_request_keys = list(catalog.sql_catalog_request_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage related key
if update_dict.has_key('request_key_list') or force:
if not force:
action = update_dict['request_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_request_keys:
sql_catalog_request_keys.append(key)
catalog.sql_catalog_request_keys = tuple(sql_catalog_request_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_request_keys = list(catalog.sql_catalog_request_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_request_keys:
sql_catalog_request_keys.remove(key)
catalog.sql_catalog_request_keys = sql_catalog_request_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
# multivalue
class CatalogMultivalueKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_multivalue_keys = list(catalog.sql_catalog_multivalue_keys)
key_list = []
for key in self._archive.keys():
if key in sql_multivalue_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Multivalue key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'multivalue_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_multivalue_keys = list(catalog.sql_catalog_multivalue_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
if update_dict.has_key('multivalue_key_list') or force:
if not force:
action = update_dict['multivalue_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_multivalue_keys:
sql_catalog_multivalue_keys.append(key)
catalog.sql_catalog_multivalue_keys = tuple(sql_catalog_multivalue_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_multivalue_keys = list(catalog.sql_catalog_multivalue_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_multivalue_keys:
sql_catalog_multivalue_keys.remove(key)
catalog.sql_catalog_multivalue_keys = sql_catalog_multivalue_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
# multivalue
class CatalogMultivalueKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_multivalue_keys'
key_list_title = 'multivalue_key_list'
key_title = 'Multivalue key'
# topic
class CatalogTopicKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_topic_search_keys = list(catalog.sql_catalog_topic_search_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_topic_search_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Topic key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'topic_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_topic_search_keys = list(catalog.sql_catalog_topic_search_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX same as related key
if update_dict.has_key('topic_key_list') or force:
if not force:
action = update_dict['topic_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_topic_search_keys:
sql_catalog_topic_search_keys.append(key)
catalog.sql_catalog_topic_search_keys = sql_catalog_topic_search_keys
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_topic_search_keys = list(catalog.sql_catalog_topic_search_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_topic_search_keys:
sql_catalog_topic_search_keys.remove(key)
catalog.sql_catalog_topic_search_keys = sql_catalog_topic_search_keys
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogScriptableKeyTemplateItem(BaseTemplateItem):
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_scriptable_keys = list(catalog.sql_catalog_scriptable_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_scriptable_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Scriptable key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'scriptable_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_scriptable_keys = list(catalog.sql_catalog_scriptable_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage scriptable key
if update_dict.has_key('scriptable_key_list') or force:
if not force:
if update_dict.has_key('scriptable_key_list'):
action = update_dict['scriptable_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_scriptable_keys:
sql_catalog_scriptable_keys.append(key)
catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_scriptable_keys = list(catalog.sql_catalog_scriptable_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_scriptable_keys:
sql_catalog_scriptable_keys.remove(key)
catalog.sql_catalog_scriptable_keys = tuple(sql_catalog_scriptable_keys)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogRoleKeyTemplateItem(BaseTemplateItem):
# XXX Copy/paste from CatalogScriptableKeyTemplateItem
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_role_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'Role key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'role_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage scriptable key
if update_dict.has_key('role_key_list') or force:
if not force:
if update_dict.has_key('role_key_list'):
action = update_dict['role_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_role_keys:
sql_catalog_role_keys.append(key)
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_role_keys = list(catalog.sql_catalog_role_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_role_keys:
sql_catalog_role_keys.remove(key)
catalog.sql_catalog_role_keys = tuple(sql_catalog_role_keys)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogLocalRoleKeyTemplateItem(BaseTemplateItem):
# XXX Copy/paste from CatalogScriptableKeyTemplateItem
def build(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
key_list = []
for key in self._archive.keys():
if key in sql_catalog_local_role_keys:
key_list.append(key)
elif not self.is_bt_for_diff:
raise NotFound, 'LocalRole key "%r" not found in catalog' %(key,)
if len(key_list) > 0:
self._objects[self.__class__.__name__+'/'+'local_role_key_list'] = key_list
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
key_list = [key.text for key in xml.getroot()]
self._objects[file_name[:-4]] = key_list
def install(self, context, trashbin, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
if context.getTemplateFormatVersion() == 1:
if len(self._objects.keys()) == 0: # needed because of pop()
return
keys = []
for k in self._objects.values().pop(): # because of list of list
keys.append(k)
else:
keys = self._archive.keys()
update_dict = kw.get('object_to_update')
force = kw.get('force')
# XXX must a find a better way to manage scriptable key
if update_dict.has_key('local_role_key_list') or force:
if not force:
if update_dict.has_key('local_role_key_list'):
action = update_dict['local_role_key_list']
if action == 'nothing':
return
for key in keys:
if key not in sql_catalog_local_role_keys:
sql_catalog_local_role_keys.append(key)
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
def uninstall(self, context, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate', 0, 'no SQL catalog was available')
return
sql_catalog_local_role_keys = list(catalog.sql_catalog_local_role_keys)
object_path = kw.get('object_path', None)
if object_path is not None:
object_keys = [object_path]
else:
object_keys = self._archive.keys()
for key in object_keys:
if key in sql_catalog_local_role_keys:
sql_catalog_local_role_keys.remove(key)
catalog.sql_catalog_local_role_keys = tuple(sql_catalog_local_role_keys)
BaseTemplateItem.uninstall(self, context, **kw)
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0:
return
path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path)
for path in self._objects.keys():
xml_data = self.generateXml(path=path)
bta.addObject(obj=xml_data, name=path, path=None)
class CatalogTopicKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_topic_search_keys'
key_list_title = 'topic_key_list'
key_title = 'Topic key'
class CatalogScriptableKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_scriptable_keys'
key_list_title = 'scriptable_key_list'
key_title = 'Scriptable key'
class CatalogRoleKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_role_keys'
key_list_title = 'role_key_list'
key_title = 'Role key'
class CatalogLocalRoleKeyTemplateItem(CatalogSearchKeyTemplateItem):
key_list_attr = 'sql_catalog_local_role_keys'
key_list_title = 'local_role_key_list'
key_title = 'LocalRole key'
class MessageTranslationTemplateItem(BaseTemplateItem):
......@@ -5004,6 +4113,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_catalog_result_key_item',
'_catalog_related_key_item',
'_catalog_result_table_item',
'_catalog_search_key_item',
'_catalog_keyword_key_item',
'_catalog_datetime_key_item',
'_catalog_full_text_key_item',
......@@ -5135,6 +4245,9 @@ Business Template is a set of definitions, such as skins, portal types and categ
PathTemplateItem(self.getTemplatePathList())
self._preference_item = \
PreferenceTemplateItem(self.getTemplatePreferenceList())
self._catalog_search_key_item = \
CatalogSearchKeyTemplateItem(
self.getTemplateCatalogSearchKeyList())
self._catalog_keyword_key_item = \
CatalogKeywordKeyTemplateItem(
self.getTemplateCatalogKeywordKeyList())
......@@ -5855,6 +4968,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
'CatalogResultKey' : '_catalog_result_key_item',
'CatalogRelatedKey' : '_catalog_related_key_item',
'CatalogResultTable' : '_catalog_result_table_item',
'CatalogSearchKey' : '_catalog_search_key_item',
'CatalogKeywordKey' : '_catalog_keyword_key_item',
'CatalogDateTimeKey' : '_catalog_datetime_key_item',
'CatalogFullTextKey' : '_catalog_full_text_key_item',
......@@ -5917,6 +5031,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_catalog_result_key_item',
'_catalog_related_key_item',
'_catalog_result_table_item',
'_catalog_search_key_item',
'_catalog_keyword_key_item',
'_catalog_datetime_key_item',
'_catalog_full_text_key_item',
......
......@@ -130,6 +130,11 @@ class BusinessTemplate:
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_catalog_search_key',
'description' : 'A list of ids of catalog search keys used by this template',
'type' : 'lines',
'mode' : 'w',
'default' : () },
{ 'id' : 'template_catalog_keyword_key',
'description' : 'A list of ids of catalog keyword keys used by this template',
'type' : 'lines',
......
......@@ -2,10 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
<tuple/>
</tuple>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
</pickle>
<pickle>
<dictionary>
......@@ -77,6 +74,7 @@
<string>my_template_catalog_method_id_list</string>
<string>my_template_catalog_result_table_list</string>
<string>my_template_catalog_result_key_list</string>
<string>my_template_catalog_search_key_list</string>
<string>my_template_catalog_keyword_key_list</string>
<string>my_template_catalog_datetime_key_list</string>
<string>my_template_catalog_role_key_list</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="LinesField" module="Products.Formulator.StandardFields"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_template_catalog_search_key_list</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
<item>
<key> <string>line_too_long</string> </key>
<value> <string>A line was too long.</string> </value>
</item>
<item>
<key> <string>required_not_found</string> </key>
<value> <string>Input is required but no input given.</string> </value>
</item>
<item>
<key> <string>too_long</string> </key>
<value> <string>You entered too many characters.</string> </value>
</item>
<item>
<key> <string>too_many_lines</string> </key>
<value> <string>You entered too many lines.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>height</string> </key>
<value> <int>5</int> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>max_length</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_linelength</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>max_lines</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>required</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Search Keys</string> </value>
</item>
<item>
<key> <string>unicode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string encoding="cdata"><![CDATA[
<br />
]]></string> </value>
</item>
<item>
<key> <string>whitespace_preserve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>width</string> </key>
<value> <int>40</int> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -1786,6 +1786,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
related_key = 'fake_id | category/catalog/z_fake_method'
result_key = 'catalog.title'
result_table = 'fake_catalog'
search_key = 'fake_search_key | FakeSearchKey'
keyword_key = 'fake_keyword'
full_text_key = 'fake_full_text'
request_key = 'fake_request'
......@@ -1817,6 +1818,13 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sql_search_related_keys.sort()
catalog.sql_catalog_related_keys = tuple(sql_search_related_keys)
self.failUnless(related_key in catalog.sql_catalog_related_keys)
# search keys
if search_key not in catalog.sql_catalog_search_keys:
sql_catalog_search_keys = list(catalog.sql_catalog_search_keys)
sql_catalog_search_keys.append(search_key)
sql_catalog_search_keys.sort()
catalog.sql_catalog_search_keys = tuple(sql_catalog_search_keys)
self.failUnless(search_key in catalog.sql_catalog_search_keys)
# keyword keys
if keyword_key not in catalog.sql_catalog_keyword_search_keys:
sql_catalog_keyword_keys = list(catalog.sql_catalog_keyword_search_keys)
......@@ -1875,7 +1883,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(local_role_key in catalog.sql_catalog_local_role_keys)
sequence.edit(related_key=related_key, result_key=result_key,
result_table=result_table,
result_table=result_table, search_key=search_key,
keyword_key=keyword_key, full_text_key=full_text_key,
request_key=request_key,
multivalue_key=multivalue_key, topic_key=topic_key, \
......@@ -1951,6 +1959,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(result_key is not None)
result_table = sequence.get('result_table', None)
self.failUnless(result_table is not None)
search_key = sequence.get('search_key', None)
self.failUnless(search_key is not None)
keyword_key = sequence.get('keyword_key', None)
self.failUnless(keyword_key is not None)
full_text_key = sequence.get('full_text_key', None)
......@@ -1971,6 +1981,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
bt.edit(template_catalog_related_key_list=[related_key],
template_catalog_result_key_list=[result_key],
template_catalog_result_table_list=[result_table],
template_catalog_search_key_list=[search_key],
template_catalog_keyword_key_list=[keyword_key],
template_catalog_full_text_key_list=[full_text_key],
template_catalog_request_key_list=[request_key],
......@@ -1991,6 +2002,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(result_key is not None)
result_table = sequence.get('result_table', None)
self.failUnless(result_table is not None)
search_key = sequence.get('search_key', None)
self.failUnless(search_key is not None)
keyword_key = sequence.get('keyword_key', None)
self.failUnless(keyword_key is not None)
full_text_key = sequence.get('full_text_key', None)
......@@ -2028,6 +2041,12 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sql_search_tables.sort()
catalog.sql_search_tables = tuple(sql_search_tables)
self.failUnless(result_table not in catalog.sql_search_tables)
# search keys
sql_catalog_search_keys = list(catalog.sql_catalog_search_keys)
sql_catalog_search_keys.remove(search_key)
sql_catalog_search_keys.sort()
catalog.sql_catalog_search_keys = tuple(sql_catalog_search_keys)
self.failUnless(search_key not in catalog.sql_catalog_search_keys)
# keyword keys
sql_catalog_keyword_keys = list(catalog.sql_catalog_keyword_search_keys)
sql_catalog_keyword_keys.remove(keyword_key)
......@@ -2087,6 +2106,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(result_key is not None)
result_table = sequence.get('result_table', None)
self.failUnless(result_table is not None)
search_key = sequence.get('search_key', None)
self.failUnless(search_key is not None)
keyword_key = sequence.get('keyword_key', None)
self.failUnless(keyword_key is not None)
full_text_key = sequence.get('full_text_key', None)
......@@ -2112,6 +2133,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(related_key in catalog.sql_catalog_related_keys)
# result table
self.failUnless(result_table in catalog.sql_search_tables)
# search key
self.failUnless(search_key in catalog.sql_catalog_search_keys)
# keyword key
self.failUnless(keyword_key in catalog.sql_catalog_keyword_search_keys)
# full text key
......@@ -2139,6 +2162,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(result_key is not None)
result_table = sequence.get('result_table', None)
self.failUnless(result_table is not None)
search_key = sequence.get('search_key', None)
self.failUnless(search_key is not None)
keyword_key = sequence.get('keyword_key', None)
self.failUnless(keyword_key is not None)
full_text_key = sequence.get('full_text_key', None)
......@@ -2164,6 +2189,8 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.failUnless(related_key not in catalog.sql_catalog_related_keys)
# result table
self.failUnless(result_table not in catalog.sql_search_tables)
# search key
self.failUnless(search_key not in catalog.sql_catalog_search_keys)
# keyword key
self.failUnless(keyword_key not in catalog.sql_catalog_keyword_search_keys)
# full text key
......
......@@ -451,6 +451,11 @@ class Catalog(Folder,
'type' : 'selection',
'select_variable' : 'getCatalogMethodIds',
'mode' : 'w' },
{ 'id': 'sql_catalog_search_keys',
'title': 'Search Key Mappings',
'description': 'A list of Search Key mappings',
'type': 'lines',
'mode': 'w' },
{ 'id' : 'sql_catalog_keyword_search_keys',
'description' : 'Columns which should be considered as full text search',
'type' : 'multiple selection',
......@@ -544,6 +549,7 @@ class Catalog(Folder,
sql_catalog_index = ''
sql_unique_values = ''
sql_catalog_paths = ''
sql_catalog_search_keys = ()
sql_catalog_keyword_search_keys = ()
sql_catalog_datetime_search_keys = ()
sql_catalog_full_text_search_keys = ()
......@@ -2265,6 +2271,12 @@ class Catalog(Folder,
LOG('SQLCatalog', WARNING, 'Ambiguous configuration: column %r is set to use %r key, but also to use %r key. Former takes precedence.' % (column, result[column], key))
else:
result[column] = key
for line in self.sql_catalog_search_keys:
try:
column, key = [x.strip() for x in line.split('|', 2)]
result[column] = key
except ValueError:
LOG('SQLCatalog', WARNING, 'Wrong configuration for sql_catalog_search_keys: %r' % line)
return result
@profiler_decorator
......
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