From 717513af6431065b5e0aa7707e62f310eb2a99bd Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Wed, 13 Oct 2010 13:31:03 +0000
Subject: [PATCH] Simplify getInstalledBusinessTemplate.

No need to accumulate a list to just return a single element based on a value
known during iteration.
No need for multiple return.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39102 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/TemplateTool.py | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py
index d87130ee98..3c5e7faeef 100644
--- a/product/ERP5/Tool/TemplateTool.py
+++ b/product/ERP5/Tool/TemplateTool.py
@@ -120,20 +120,19 @@ class TemplateTool (BaseTool):
       # However, that unlikely happens, and using a Z SQL Method has a
       # potential danger because business templates may exchange catalog
       # methods, so the database could be broken temporarily.
-      replaced_list = []
-      replaced_list_append = replaced_list.append
+      latest_bt = None
+      latest_revision = 0
       for bt in self.contentValues(filter={'portal_type':'Business Template'}):
         if bt.getTitle() == title:
           installation_state = bt.getInstallationState()
           if installation_state == 'installed':
-            return bt
+            latest_bt = bt
+            break
           elif strict is False and installation_state == 'replaced':
-            replaced_list_append((bt.getId(), bt.getRevision()))
-      # still there means that we might search for a replaced bt
-      if len(replaced_list):
-        replaced_list.sort(key=lambda x: -int(x[1]))
-        return self._getOb(replaced_list[0][0])
-      return None
+            revision = int(bt.getRevision())
+            if revision > latest_revision:
+              latest_bt = bt
+      return latest_bt
 
     def getInstalledBusinessTemplatesList(self):
       """Deprecated.
-- 
2.30.9