Commit c2f6c590 authored by Ayush Tiwari's avatar Ayush Tiwari

Catalog, Business Template: Remove expression_instance property from CatalogFilter property sheets

Also, while exporting catalog methods, explicitly check for `expression_instance` property.
Now we keep expression_instance property in a volatile attribute, so we should prefer using
it.
parent a1797e75
...@@ -116,7 +116,6 @@ catalog_method_list = ('_is_catalog_list_method_archive', ...@@ -116,7 +116,6 @@ catalog_method_list = ('_is_catalog_list_method_archive',
'_is_filtered_archive',) '_is_filtered_archive',)
catalog_method_filter_list = ('_filter_expression_archive', catalog_method_filter_list = ('_filter_expression_archive',
'_filter_expression_instance_archive',
'_filter_expression_cache_key_archive', '_filter_expression_cache_key_archive',
'_filter_type_archive',) '_filter_type_archive',)
...@@ -616,8 +615,12 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -616,8 +615,12 @@ class BaseTemplateItem(Implicit, Persistent):
# PythonScript covers both Zope Python scripts # PythonScript covers both Zope Python scripts
# and ERP5 Python Scripts # and ERP5 Python Scripts
if isinstance(obj, PythonScript): if isinstance(obj, PythonScript):
# `expression_instance` is included so as to add compatibility for
# exporting older catalog methods which might have them as their
# properties or in their attribute dict.
attr_set.update(('func_code', 'func_defaults', '_code', attr_set.update(('func_code', 'func_defaults', '_code',
'_lazy_compilation', 'Python_magic')) '_lazy_compilation', 'Python_magic',
'expression_instance'))
for attr in 'errors', 'warnings', '_proxy_roles': for attr in 'errors', 'warnings', '_proxy_roles':
if not obj.__dict__.get(attr, 1): if not obj.__dict__.get(attr, 1):
delattr(obj, attr) delattr(obj, attr)
...@@ -625,7 +628,10 @@ class BaseTemplateItem(Implicit, Persistent): ...@@ -625,7 +628,10 @@ class BaseTemplateItem(Implicit, Persistent):
attr_set.update(('_EtagSupport__etag', 'size')) attr_set.update(('_EtagSupport__etag', 'size'))
# SQL covers both ZSQL Methods and ERP5 SQL Methods # SQL covers both ZSQL Methods and ERP5 SQL Methods
elif isinstance(obj, SQL): elif isinstance(obj, SQL):
attr_set.update(('_arg', 'template')) # `expression_instance` is included so as to add compatibility for
# exporting older catalog methods which might have them as their
# properties or in their attribute dict.
attr_set.update(('_arg', 'template', 'expression_instance'))
elif interfaces.IIdGenerator.providedBy(obj): elif interfaces.IIdGenerator.providedBy(obj):
attr_set.update(('last_max_id_dict', 'last_id_dict')) attr_set.update(('last_max_id_dict', 'last_id_dict'))
elif classname == 'Types Tool' and klass.__module__ == 'erp5.portal_type': elif classname == 'Types Tool' and klass.__module__ == 'erp5.portal_type':
...@@ -3068,14 +3074,8 @@ class CatalogMethodTemplateItem(ObjectTemplateItem): ...@@ -3068,14 +3074,8 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
# migration. # migration.
if self._is_filtered_archive.get(method_id, 0): if self._is_filtered_archive.get(method_id, 0):
expression = self._filter_expression_archive[method_id] expression = self._filter_expression_archive[method_id]
if expression and expression.strip():
# only compile non-empty expressions
expr_instance = Expression(expression)
else:
expr_instance = None
method.setFiltered(1) method.setFiltered(1)
method.setExpression(expression) method.setExpression(expression)
method.setExpressionInstance(expr_instance)
method.setExpressionCacheKey( method.setExpressionCacheKey(
self._filter_expression_cache_key_archive.get(method_id, ())) self._filter_expression_cache_key_archive.get(method_id, ()))
method.setTypeList(self._filter_type_archive.get(method_id, ())) method.setTypeList(self._filter_type_archive.get(method_id, ()))
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/object</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>expression_instance_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -423,7 +423,6 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -423,7 +423,6 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
new_method.setTypeList(filter_['type']) new_method.setTypeList(filter_['type'])
new_method.setExpressionCacheKeyList(filter_['expression_cache_key']) new_method.setExpressionCacheKeyList(filter_['expression_cache_key'])
new_method.setExpression(filter_['expression']) new_method.setExpression(filter_['expression'])
new_method.setExpressionInstance(filter_['expression_instance'])
# Delete filter_dict before migration of catalog object(s) # Delete filter_dict before migration of catalog object(s)
del obj.filter_dict del obj.filter_dict
......
...@@ -3261,7 +3261,6 @@ class TestAccessControl(ERP5TypeTestCase): ...@@ -3261,7 +3261,6 @@ class TestAccessControl(ERP5TypeTestCase):
method = self.getCatalogTool().getSQLCatalog()._getOb('z_catalog_object_list') method = self.getCatalogTool().getSQLCatalog()._getOb('z_catalog_object_list')
method.setFiltered(1) method.setFiltered(1)
method.setExpression(self.expression) method.setExpression(self.expression)
method.setExpressionInstance(Expression(self.expression))
createZODBPythonScript(self.getSkinsTool().custom, createZODBPythonScript(self.getSkinsTool().custom,
'Base_immediateReindexObject', 'Base_immediateReindexObject',
......
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