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

Optimize using cache method

parent 4c6d54c2
......@@ -53,7 +53,8 @@
<value> <string>"""\n
Find default image for a given resource. If no image\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
TODO:\n
- make the variation support generic (remove hardcoded "variation"\n
......@@ -74,13 +75,24 @@ if default_image is not None:\n
return default_image.absolute_url()\n
\n
if \'variation\' in context.getVariationBaseCategoryList():\n
default_variation = context.getVariationRangeCategoryList(base_category_list=[\'variation\'])\n
if len(default_variation):\n
default_variation = default_variation[0]\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()\n
\n
def getDefaultVariation():\n
import random\n
default_variation = context.getVariationRangeCategoryList(base_category_list=[\'variation\'])\n
if len(default_variation):\n
var_count = len(default_variation)\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
return None\n
</string> </value>
......
296
\ No newline at end of file
297
\ 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