Commit 13f13eb8 authored by Ivan Tyagov's avatar Ivan Tyagov

Use ZSQLCatalog to filter convertable documents.

Use getTypeBasedMethod and unify handlers.
parent a0ee2634
......@@ -2,4 +2,13 @@
<item key="sql_catalog_object_list" type="int">
<value>1</value>
</item>
<item key="_is_filtered_archive" type="int">
<value>1</value>
</item>
<item key="_filter_expression_archive" type="str">
<value>python: context.isDocument()</value>
</item>
<item key="_filter_expression_cache_key_archive" type="tuple">
<value>portal_type</value>
</item>
</catalog_method>
......@@ -51,7 +51,6 @@
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
portal_id = portal.getId()\n
MARKER = (None, \'\',)\n
\n
address = portal.portal_preferences.getPreferredOoodocServerAddress()\n
......@@ -61,18 +60,16 @@ port = portal.portal_preferences.getPreferredOoodocServerPortNumber()\n
# is installed BEFORE the real cloudoo is setup in preferences.\n
if address not in MARKER and port not in MARKER:\n
for index_uid in range(len(uid)):\n
document_relative_url = getPath[index_uid].replace("/%s/" %portal_id, "")\n
document_relative_url = getRelativeUrl[index_uid]\n
document = portal.restrictedTraverse(document_relative_url)\n
if getattr(document, "convert", None) is not None and \\\n
getattr(document, "getData", None) is not None and \\\n
(document.getData() not in MARKER or document.getBaseData() not in MARKER):\n
if (document.getData() not in MARKER or document.getBaseData() not in MARKER):\n
#context.log("preconvert %s" %document.getRelativeUrl())\n
document.activate(serialize_tag="conversion").Base_preConvert()\n
document.activate(serialize_tag="conversion").Base_callPreConvert()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>uid, getPath</string> </value>
<value> <string>uid, getRelativeUrl</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -51,32 +51,30 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Do actual conversion of any Document type.\n
Pre convert to know good defaults.\n
Use type based methods to allow finer granularity (for example in case of PDF we support many frames inside a document).\n
"""\n
portal = context.getPortalObject()\n
\n
format_kw = {\'format\': format,\n
\'quality\': quality}\n
for display in display_list:\n
format_kw[\'display\'] = display\n
context.convert(**format_kw)\n
portal_type = context.getPortalType()\n
format = portal.portal_preferences.getPreferredImageFormat()\n
quality = portal.portal_preferences.getPreferredImageQuality()\n
preferred_image_size = portal.portal_preferences.getPreferredImageSize()\n
\n
# thumbnail is required always\n
display_list = ["thumbnail"]\n
method = context.getTypeBasedMethod(\'preConvert\')\n
context.log(method)\n
return method(**dict(format=format, quality=quality, display_list = display_list))\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>format, quality, display_list</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_preConvert</string> </value>
<value> <string>Base_callPreConvert</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -51,26 +51,28 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Pre convert to know good defaults.\n
Use type based methods to allow finer granularity (for example in case of PDF we support many frames inside a document).\n
Do actual conversion of any Base type.\n
"""\n
portal = context.getPortalObject()\n
\n
portal_type = context.getPortalType()\n
format = portal.portal_preferences.getPreferredImageFormat()\n
quality = portal.portal_preferences.getPreferredImageQuality()\n
preferred_image_size = portal.portal_preferences.getPreferredImageSize()\n
\n
# thumbnail is required always\n
display_list = ["thumbnail"]\n
method_id = \'%s_preConvert\' %portal_type.replace(\' \', \'\')\n
method = getattr(context, method_id, context.Document_preConvert)\n
return method(**dict(format=format, quality=quality, display_list = display_list))\n
format_kw = {\'format\': format,\n
\'quality\': quality}\n
for display in display_list:\n
format_kw[\'display\'] = display\n
context.convert(**format_kw)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>format, quality, display_list</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -56,7 +56,7 @@
It will do that recursively in entire ERP5 instance.\n
\n
"""\n
context.ERP5Site_checkDataWithScript("Base_preConvert", \n
context.ERP5Site_checkDataWithScript("Base_callPreConvert", \n
tag="pre_convert",\n
packet=2,\n
id_list=["document_module", "image_module"])\n
......
......@@ -51,10 +51,9 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Do actual conversion of Spreadsheet type.\n
Do actual conversion of any Image type.\n
"""\n
context.convert(**{\'format\': \'html\'})\n
context.Document_preConvert(format, quality, display_list)\n
context.Base_preConvert(format, quality, display_list)\n
</string> </value>
</item>
<item>
......@@ -71,7 +70,7 @@ context.Document_preConvert(format, quality, display_list)\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Text_preConvert</string> </value>
<value> <string>Image_preConvert</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -54,7 +54,7 @@
Do actual conversion of Spreadsheet type.\n
"""\n
context.convert(**{\'format\': \'html\'})\n
context.Document_preConvert(format, quality, display_list)\n
context.Base_preConvert(format, quality, display_list)\n
</string> </value>
</item>
<item>
......@@ -71,7 +71,7 @@ context.Document_preConvert(format, quality, display_list)\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Spreadsheet_preConvert</string> </value>
<value> <string>OOoDocument_preConvert</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -51,10 +51,9 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Do actual conversion of Spreadsheet type.\n
Do actual conversion of any Image type.\n
"""\n
context.convert(**{\'format\': \'html\'})\n
context.Document_preConvert(format, quality, display_list)\n
context.Base_preConvert(format, quality, display_list)\n
</string> </value>
</item>
<item>
......@@ -71,7 +70,7 @@ context.Document_preConvert(format, quality, display_list)\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Drawing_preConvert</string> </value>
<value> <string>TextDocument_preConvert</string> </value>
</item>
</dictionary>
</pickle>
......
5
\ No newline at end of file
6
\ 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