Commit 717513af authored by Vincent Pelletier's avatar Vincent Pelletier

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