Commit e6ef8520 authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Xiaowu Zhang

Optimize using cache method

parent 4c6d54c2
...@@ -53,7 +53,8 @@ ...@@ -53,7 +53,8 @@
<value> <string>"""\n <value> <string>"""\n
Find default image for a given resource. If no image\n Find default image for a given resource. If no image\n
is defined on the resource itself, look in each individual\n is defined on the resource itself, look in each individual\n
variation.\n variation. Take a random variation (to increase site \n
appeal)\n
\n \n
TODO:\n TODO:\n
- make the variation support generic (remove hardcoded "variation"\n - make the variation support generic (remove hardcoded "variation"\n
...@@ -74,13 +75,24 @@ if default_image is not None:\n ...@@ -74,13 +75,24 @@ if default_image is not None:\n
return default_image.absolute_url()\n return default_image.absolute_url()\n
\n \n
if \'variation\' in context.getVariationBaseCategoryList():\n if \'variation\' in context.getVariationBaseCategoryList():\n
default_variation = context.getVariationRangeCategoryList(base_category_list=[\'variation\'])\n \n
if len(default_variation):\n def getDefaultVariation():\n
default_variation = default_variation[0]\n import random\n
default_variation = default_variation[len(\'variation/\'):]\n default_variation = context.getVariationRangeCategoryList(base_category_list=[\'variation\'])\n
default_image = context.getPortalObject().restrictedTraverse(default_variation).getDefaultImageValue()\n if len(default_variation):\n
if default_image is not None:\n var_count = len(default_variation)\n
return default_image.absolute_url()\n default_variation = default_variation[random.randint(0, var_count - 1)]\n
default_variation = default_variation[len(\'variation/\'):]\n
default_image = context.getPortalObject().restrictedTraverse(default_variation).getDefaultImageValue()\n
if default_image is not None:\n
return default_image.absolute_url(), default_variation\n
return None\n
\n
from Products.ERP5Type.Cache import CachingMethod\n
url, default_variation = CachingMethod(getDefaultVariation, id=(\'Resource_getDefaultVariation2\', context.getId()), cache_factory=\'erp5_content_long\')()\n
if default_variation: \n
context.REQUEST.set(\'default_displayed_variation\', default_variation) # Pass the value to other widgets\n
return url\n
\n \n
return None\n return None\n
</string> </value> </string> </value>
......
296 297
\ 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