From d09f55281111befb470a9697f7a03c8f5626dd97 Mon Sep 17 00:00:00 2001
From: Ivan Tyagov <ivan@nexedi.com>
Date: Tue, 25 Oct 2011 15:57:47 +0300
Subject: [PATCH] Add script to generate proper URL for image conversion which
 can be reused in other UI parts.

---
 .../Base_getImageArgumentDict.xml             | 84 +++++++++++++++++++
 .../Document_getSummaryAsHTML.xml             |  7 +-
 bt5/erp5_web/bt/revision                      |  2 +-
 3 files changed, 89 insertions(+), 4 deletions(-)
 create mode 100644 bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Base_getImageArgumentDict.xml

diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Base_getImageArgumentDict.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Base_getImageArgumentDict.xml
new file mode 100644
index 0000000000..f936b1772c
--- /dev/null
+++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Base_getImageArgumentDict.xml
@@ -0,0 +1,84 @@
+<?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
+  A core method that will return default image conversion arguments as a dict.\n
+"""\n
+portal = context.getPortalObject()\n
+portal_preferences = portal.portal_preferences\n
+image_argument_dict = {\'format\': portal_preferences.getPreferredImageFormat(),\n
+                       \'quality\': portal_preferences.getPreferredImageQuality()}\n
+\n
+pre_converted_only = portal_preferences.getPreferredPreConvertedOnly()\n
+if pre_converted_only:\n
+  # only add if it\'s True as conversion machine assume that if it is missing\n
+  # then conversion should happen "on the fly"\n
+  image_argument_dict[\'pre_converted_only\'] = pre_converted_only\n
+\n
+if context.getPortalType() in (\'PDF\',):\n
+  # PDF support frames\n
+  image_argument_dict[\'frame\'] = 0\n
+return image_argument_dict\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Base_getImageArgumentDict</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Document_getSummaryAsHTML.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Document_getSummaryAsHTML.xml
index b8fcf723a6..913b280777 100644
--- a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Document_getSummaryAsHTML.xml
+++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/Document_getSummaryAsHTML.xml
@@ -39,11 +39,12 @@
 <tal:block \n
   tal:define="document_url here/absolute_url;\n
               thumbnail_url here/Base_getThumbnailAbsoluteUrl;\n
-              display string:thumbnail;\n
               icon here/getIconURL;\n
               title here/getTitle;\n
               modification_date python: here.Base_FormatDate(here.getModificationDate(),hour_minute=1);\n
-              format python: here.getObject().portal_preferences.getPreference(\'preferred_image_format\', \'png\');\n
+              image_conversion_dict here/Base_getImageArgumentDict;\n
+              dummy python: image_conversion_dict.update(**{\'display\':\'thumbnail\'});\n
+              image_conversion_arguments python: \'&\'.join([\'%s=%s\' % (k, v) for k, v in image_conversion_dict.items()]);\n
               description python: here.getDescription();\n
               box_relative_url python: request.get(\'box_relative_url\', \'\');\n
               dom_id python: modules[\'base64\'].urlsafe_b64encode(\'%s-%s\' %(box_relative_url, here.getUid())).rstrip(\'=\')">\n
@@ -68,7 +69,7 @@
        tal:attributes="href string:${document_url}/view">\n
       <img alt="Thumbnail" class="document-thumbnail"\n
          tal:condition="python: thumbnail_url is not None"\n
-         tal:attributes="src string:${thumbnail_url}/index_html?display=${display}&format=${format}"/>\n
+         tal:attributes="src string:${thumbnail_url}/index_html?${image_conversion_arguments}"/>\n
       <br/>\n
       <span class="description"\n
             tal:content="description"/>\n
diff --git a/bt5/erp5_web/bt/revision b/bt5/erp5_web/bt/revision
index c9d864be1c..1286216edf 100644
--- a/bt5/erp5_web/bt/revision
+++ b/bt5/erp5_web/bt/revision
@@ -1 +1 @@
-1066
\ No newline at end of file
+1067
\ No newline at end of file
-- 
2.30.9