Commit 5d1fe7a0 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

bt5_config: Override sub for comparing 2 Business Manager objects

parent 5bd4952f
...@@ -320,6 +320,7 @@ class BusinessManager(XMLObject): ...@@ -320,6 +320,7 @@ class BusinessManager(XMLObject):
""" """
Adds the Business Item objects for the given Business Manager objects Adds the Business Item objects for the given Business Manager objects
""" """
import pdb; pdb.set_trace()
self._path_item_list.extend(other._path_item_list) self._path_item_list.extend(other._path_item_list)
template_path_list = list(self.template_path_list)+list(other.template_path_list) template_path_list = list(self.template_path_list)+list(other.template_path_list)
self.template_path_list = template_path_list self.template_path_list = template_path_list
...@@ -327,6 +328,18 @@ class BusinessManager(XMLObject): ...@@ -327,6 +328,18 @@ class BusinessManager(XMLObject):
__radd__ = __add__ __radd__ = __add__
def __sub__(self, other):
"""
Override subtract to find difference b/w the values in different cases.
"""
# Reverse the sign of Business Item objects for the old Business Manager
for path_item in other._path_item_list:
path_item._sign = -1
self._path_item_list.append(path_item)
return self
__rsub__ = __add__
security.declareProtected(Permissions.ManagePortal, 'storeTemplateData') security.declareProtected(Permissions.ManagePortal, 'storeTemplateData')
def storeTemplateData(self): def storeTemplateData(self):
""" """
...@@ -787,7 +800,6 @@ class BusinessItem(Implicit, Persistent): ...@@ -787,7 +800,6 @@ class BusinessItem(Implicit, Persistent):
return merged_value return merged_value
def _guessFilename(self, document, key, data): def _guessFilename(self, document, key, data):
""" """
Try to guess the extension based on the id of the document Try to guess the extension based on the id of the document
......
...@@ -314,6 +314,7 @@ class TemplateTool (BaseTool): ...@@ -314,6 +314,7 @@ class TemplateTool (BaseTool):
self.deleteContent(id) self.deleteContent(id)
self._importObjectFromFile(StringIO(export_string), id=id) self._importObjectFromFile(StringIO(export_string), id=id)
security.declareProtected( Permissions.ManagePortal, 'manage_download' ) security.declareProtected( Permissions.ManagePortal, 'manage_download' )
def manage_download(self, url, id=None, REQUEST=None): def manage_download(self, url, id=None, REQUEST=None):
"""The management interface for download. """The management interface for download.
...@@ -1693,9 +1694,52 @@ class TemplateTool (BaseTool): ...@@ -1693,9 +1694,52 @@ class TemplateTool (BaseTool):
""" """
Run installation on flattened Business Manager Run installation on flattened Business Manager
""" """
combinedBM = self.combineMultipleBusinessManager(bm_list) final_bm_list = []
installed_bm_list = self.getInstalledBusinessManagerList()
installed_bm_title_list = self.getInstalledBusinessManagerTitleList()
installed_bm_dict = dict(zip(installed_bm_title_list, installed_bm_list))
import pdb; pdb.set_trace()
for bm in bm_list:
if bm.title in installed_bm_title_list:
# Not very suitable way to look for already installed BM
installed_bm = installed_bm_dict[bm.title]
# XXX: Installed BM is already reduced. For the Business Manager we
# are planning to install, we should reduce it also.
compared_bm = self.compareBusinessManager(bm, installed_bm)
final_bm_list.append(compared_bm)
else:
final_bm_list.append(bm)
combinedBM = self.combineMultipleBusinessManager(final_bm_list)
self.installBusinessManager(combinedBM) self.installBusinessManager(combinedBM)
# Explicilty change the status of Business Manager which are installed
for bm in bm_list:
bm.setStatus('installed')
def getInstalledBusinessManagerList(self):
bm_list = self.objectValues(portal_type='Business Manager')
installed_bm_list = [bm for bm in bm_list if bm.getStatus() == 'installed']
return installed_bm_list
def getInstalledBusinessManagerTitleList(self):
installed_bm_list = self.getInstalledBusinessManagerList()
if not len(installed_bm_list):
return []
installed_bm_title_list = [bm.title for bm in installed_bm_list]
return installed_bm_title_list
security.declareProtected(Permissions.ManagePortal,
'compareMultipleBusinessManager')
def compareBusinessManager(self, new_bm, old_bm):
"""
Compare two business manager and return a new Business manager based on
the difference. This is specially required to comapre two versions of
Business Manager(s).
"""
compared_bm = new_bm-old_bm
return compared_bm
security.declareProtected(Permissions.ManagePortal, security.declareProtected(Permissions.ManagePortal,
'getBusinessTemplateUrl') 'getBusinessTemplateUrl')
......
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