Commit 8a7186da authored by Nicolas Dumazet's avatar Nicolas Dumazet

Quantity Unit Definitions: Performance & backward-compatibility (1/2)

* Add a (failing) test where the old system is used for quantities
* Use a cached Python Script to keep the universal quantity definitions:
  * erp5_content_long
  * delete the cache when a global quantity definition is changed via an
    interaction workflow on Definitions
  * Use the catalog to retrieve the global definitions
  * If no Quantity Definitions are defined _at all_, then it falls
    back and uses the properties on categories


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32166 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 31b02386
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>def getUniversalQuantityUnitDefinitionDict():\n
\n
kw = dict(portal_type="Quantity Unit Conversion Definition",\n
grand_parent_portal_type="Quantity Unit Conversion Module")\n
\n
result = {}\n
for definition in context.portal_catalog(**kw):\n
definition = definition.getObject()\n
definition_list = definition.getParentValue()\n
standard_quantity_unit_uid = definition_list.getQuantityUnitUid()\n
if standard_quantity_unit_uid is None:\n
continue\n
\n
result[standard_quantity_unit_uid] = (None, 1.0)\n
unit_uid = definition.getQuantityUnitUid()\n
if unit_uid is None:\n
continue\n
quantity = definition.getQuantity()\n
if not quantity:\n
continue\n
result[unit_uid] = (definition.getUid(), quantity)\n
\n
return result\n
\n
def getCategoryQuantityUnitDefinitionDict():\n
quantity_unit = context.portal_categories.quantity_unit\n
result = {}\n
for obj in quantity_unit.getCategoryMemberValueList(portal_type="Category"):\n
obj = obj.getObject()\n
quantity = obj.getProperty(\'quantity\')\n
if quantity is not None:\n
result[obj.getUid()] = (None, float(quantity))\n
\n
return result\n
\n
def getQuantityUnitDefinitionDict():\n
result = getUniversalQuantityUnitDefinitionDict()\n
if not result:\n
result = getCategoryQuantityUnitDefinitionDict()\n
return result\n
\n
from Products.ERP5Type.Cache import CachingMethod\n
return CachingMethod(getQuantityUnitDefinitionDict,\n
"getUniversalQuantityUnitDefinitionDict",\n
cache_factory="erp5_content_long")()\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>getUniversalQuantityUnitDefinitionDict</string>
<string>getCategoryQuantityUnitDefinitionDict</string>
<string>getQuantityUnitDefinitionDict</string>
<string>Products.ERP5Type.Cache</string>
<string>CachingMethod</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>QuantityUnitConversionModule_getUniversalDefinitionDict</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Cache import CachingMethod\n
def foo(): pass\n
cached = CachingMethod(foo,\n
"getUniversalQuantityUnitDefinitionDict",\n
cache_factory="erp5_content_long")\n
\n
cached.delete()\n
\n
context.QuantityUnitConversionModule_getUniversalDefinitionDict()\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>Products.ERP5Type.Cache</string>
<string>CachingMethod</string>
<string>foo</string>
<string>cached</string>
<string>_getattr_</string>
<string>context</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>QuantityUnitConversionModule_invalidateUniversalDefinitionDict</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -66,6 +66,8 @@ else:\n ...@@ -66,6 +66,8 @@ else:\n
# This was a global definition.\n # This was a global definition.\n
# Its change implies that all local definitions need reindexation\n # Its change implies that all local definitions need reindexation\n
# Even resources that do NOT override definitions need indexation.\n # Even resources that do NOT override definitions need indexation.\n
context.activate(tag="QuantityUnitConversionDefinition_reindexResource", **activate_kw).QuantityUnitConversionModule_invalidateUniversalDefinitionDict()\n
activate_kw["after_tag"] = "QuantityUnitConversionDefinition_reindexResource"\n
context.product_module.recursiveReindexObject(activate_kw=activate_kw)\n context.product_module.recursiveReindexObject(activate_kw=activate_kw)\n
</string> </value> </string> </value>
</item> </item>
...@@ -110,7 +112,9 @@ else:\n ...@@ -110,7 +112,9 @@ else:\n
<string>grand_parent</string> <string>grand_parent</string>
<string>dict</string> <string>dict</string>
<string>activate_kw</string> <string>activate_kw</string>
<string>_apply_</string>
<string>context</string> <string>context</string>
<string>_write_</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
439 440
\ No newline at end of file \ No newline at end of file
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