Commit 00942065 authored by Jean-Paul Smets's avatar Jean-Paul Smets Committed by Xiaowu Zhang

Use Resource_getWebShopImageURL to test/display image

A resource image can be defined in the Resource itself or in its variations. The easiest way to test if any image exists is to try to get its URL.
parent 2a772e64
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</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>"""\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
\n
TODO:\n
- make the variation support generic (remove hardcoded "variation"\n
and use another approach to select default variation based\n
for example on a default variation order or int_index)\n
- make this script cached per transaction\n
"""\n
request = context.REQUEST\n
variation = request.get(\'variation\', None)\n
if variation:\n
variation = context.getWebSiteValue().restrictedTraverse(variation)\n
image = variation.getDefaultImageValue()\n
if image is not None:\n
return image.absolute_url()\n
\n
default_image = context.getDefaultImageValue()\n
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
return None\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Resource_getWebShopImageURL</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Return a URL for current product image</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -298,16 +298,13 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.getDefaultImageValue() in (None, \'\') or here.getDefaultImageValue().getData() in (None, \'\')</string> </value>
<value> <string>python: not here.Resource_getWebShopImageURL()</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -14,6 +14,7 @@
<string>default</string>
<string>description</string>
<string>enabled</string>
<string>image_display</string>
<string>title</string>
</list>
</value>
......@@ -62,7 +63,9 @@
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -71,7 +74,7 @@
<item>
<key> <string>enabled</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
......@@ -82,6 +85,10 @@
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>image_display</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
......@@ -121,6 +128,10 @@
<key> <string>form_id</string> </key>
<value> <string>File_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>image_display</string> </key>
<value> <string>small</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
......@@ -137,16 +148,26 @@
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.getDefaultImageValue() not in (None, \'\') and here.getDefaultImageValue().getData() not in (None, \'\')</string> </value>
<value> <string>python: here.Resource_getWebShopImageURL()</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Resource_getWebShopImageURL()</string> </value>
</item>
</dictionary>
</pickle>
......
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