From 1b54e7e8d335ed9707a96322aaea454fff1d67a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 13 Apr 2007 14:03:10 +0000
Subject: [PATCH] add compatibility support for old versions of oood without
 getAllowedTargetList method.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14070 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5OOo/Document/OOoDocument.py | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/product/ERP5OOo/Document/OOoDocument.py b/product/ERP5OOo/Document/OOoDocument.py
index 30b672a7f0..0864f5d26c 100644
--- a/product/ERP5OOo/Document/OOoDocument.py
+++ b/product/ERP5OOo/Document/OOoDocument.py
@@ -32,6 +32,7 @@ import re
 import zipfile
 import cStringIO
 import socket
+from warnings import warn
 from DateTime import DateTime
 
 from AccessControl import ClassSecurityInfo
@@ -176,7 +177,8 @@ class OOoDocument(File, ConversionCacheMixin):
                                          allow_none=True)
     return server_proxy
 
-  security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList')
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            'getTargetFormatItemList')
   def getTargetFormatItemList(self):
     """
       Returns a list of acceptable formats for conversion
@@ -187,13 +189,22 @@ class OOoDocument(File, ConversionCacheMixin):
     """
     def cached_getTargetFormatItemList(content_type):
       server_proxy = self._mkProxy()
-      allowed = server_proxy.getAllowedTargetItemList(content_type) # oood API needs naming convention update
-      return [(y, x) for x, y in allowed] # tuple order is reversed to be compatible with ERP5 Form
+      try:
+        allowed = server_proxy.getAllowedTargetItemList(content_type)
+      except Fault, f:
+        allowed = server_proxy.getAllowedTargets(content_type)
+        warn('Your oood version is too old, using old method '
+            'getAllowedTargets instead of getAllowedTargetList',
+            DeprecationWarning)
+
+      # tuple order is reversed to be compatible with ERP5 Form
+      return [(y, x) for x, y in allowed]
 
     # Cache valid format list
-    cached_getTargetFormatItemList = CachingMethod(cached_getTargetFormatItemList,
-                                        id = "OOoDocument_getTargetFormatItemList",
-                                                   cache_factory='erp5_ui_medium')
+    cached_getTargetFormatItemList = CachingMethod(
+                                cached_getTargetFormatItemList,
+                                id="OOoDocument_getTargetFormatItemList",
+                                cache_factory='erp5_ui_medium')
 
     return cached_getTargetFormatItemList(self.getBaseContentType())
 
-- 
2.30.9