Commit 33d8f350 authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_catalog: Use getattr to get catalog attributes

One of the difference between SQL and ERP5 Catalog is how they
handle their properties. For ERP5Catalog, we use property_sheets
which generate setters and getters, for SQLCatalog, properties
just act as attributes(as one can expect from a property set
on a class).

This creates a difference on how we use them, especially for
list_type properties, which have accessors like get<PropertyName>List
to get the list of objects. For SQLCatalog, there is no such thing.
This creates problem whereever 'get<PropertyName>' or getProperty(<name>)
was being used to get multiple property types.

So, we changed this to rely on getattr for the Python Scripts in this
commit. Note that, getattr isn't good if we care about performance,
but given that its used only twice, this can be better than adding
extra function overhead.
parent ee3a4975
......@@ -3,8 +3,8 @@ portal = context.getPortalObject()
# This scriptable key supports content_translation if the table is present
catalog = portal.portal_catalog.getSQLCatalog()
if 'content_translation' in catalog.getProperty('sql_search_tables'):
if [x for x in catalog.getProperty('sql_catalog_search_keys', []) if 'Mroonga' in x]:
if 'content_translation' in getattr(catalog, 'sql_search_tables', []):
if [x for x in getattr(catalog, 'sql_catalog_search_keys', []) if 'Mroonga' in x]:
return AndQuery(SimpleQuery(**{'content_translation.translated_text': value, 'comparison_operator': 'mroonga_boolean'}),
Query(**{'content_translation.property_name': 'title'}))
else:
......
......@@ -59,7 +59,7 @@ class CatalogKeywordKeyConfiguratorItem(ConfiguratorItemMixin, XMLObject):
error_list = []
portal = self.getPortalObject()
catalog = portal.portal_catalog.getSQLCatalog()
key_list = list(catalog.getProperty('sql_catalog_keyword_search_keys', ()))
key_list = list(getattr(catalog, 'sql_catalog_keyword_search_keys', ()))
for k in self.key_list:
if k not in key_list:
error_list.append(self._createConstraintMessage(
......
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