Do not fail batch imports if one of elements fails to be imported

This commit is contained in:
DarkPhoenix
2019-08-21 18:16:27 +03:00
parent b4789bbebf
commit 93af60c3d0
5 changed files with 21 additions and 24 deletions

View File

@@ -17,12 +17,11 @@ class GuiImportBoostersCommand(wx.Command):
self.boosters = set(b[0] for b in boosters)
def Do(self):
if not self.boosters:
return False
commands = []
results = []
for itemID in self.boosters:
commands.append(CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=BoosterInfo(itemID=itemID)))
success = self.internalHistory.submitBatch(*commands)
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=BoosterInfo(itemID=itemID))
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.flush()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)

View File

@@ -20,12 +20,11 @@ class GuiImportCargosCommand(wx.Command):
self.cargos[itemID] += amount
def Do(self):
if not self.cargos:
return False
commands = []
results = []
for itemID, amount in self.cargos.items():
commands.append(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=itemID, amount=amount)))
success = self.internalHistory.submitBatch(*commands)
cmd = CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=itemID, amount=amount))
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
return success

View File

@@ -28,10 +28,11 @@ class GuiImportImplantsCommand(wx.Command):
successSource = self.internalHistory.submit(cmd)
else:
successSource = False
commands = []
resultsImplants = []
for itemID in self.implants:
commands.append(CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=itemID)))
successImplants = self.internalHistory.submitBatch(*commands)
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=itemID))
resultsImplants.append(self.internalHistory.submit(cmd))
successImplants = any(resultsImplants)
# Acceptable behavior when we already have passed implant and just switch source, or
# when we have source and add implant, but not if we do not change anything
success = successSource or successImplants

View File

@@ -17,15 +17,14 @@ class GuiImportLocalDronesCommand(wx.Command):
self.drones = drones
def Do(self):
if not self.drones:
return False
commands = []
results = []
for itemID, amount in self.drones:
commands.append(CalcAddLocalDroneCommand(
cmd = CalcAddLocalDroneCommand(
fitID=self.fitID,
droneInfo=DroneInfo(itemID=itemID, amount=amount, amountActive=0),
forceNewStack=True))
success = self.internalHistory.submitBatch(*commands)
forceNewStack=True)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.flush()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)

View File

@@ -17,12 +17,11 @@ class GuiImportLocalFightersCommand(wx.Command):
self.fighters = fighters
def Do(self):
if not self.fighters:
return False
commands = []
results = []
for itemID, amount in self.fighters:
commands.append(CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=FighterInfo(itemID=itemID, amount=amount, state=False)))
success = self.internalHistory.submitBatch(*commands)
cmd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=FighterInfo(itemID=itemID, amount=amount, state=False))
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.flush()
sFit = Fit.getInstance()
sFit.recalc(self.fitID)