Better way to fix deletion of projection relationships
This commit is contained in:
@@ -66,7 +66,7 @@ from eos.db.saveddata.queries import getUser, getCharacter, getFit, getFitsWithS
|
||||
getCharacterList, getPrice, getDamagePatternList, getDamagePattern, \
|
||||
getFitList, getFleetList, getFleet, save, remove, commit, add, \
|
||||
getCharactersForUser, getMiscData, getSquadsIDsWithFitID, getWing, \
|
||||
getSquad, getBoosterFits
|
||||
getSquad, getBoosterFits, getProjectedFits
|
||||
|
||||
#If using in memory saveddata, you'll want to reflect it so the data structure is good.
|
||||
if config.saveddata_connectionstring == "sqlite:///:memory:":
|
||||
|
||||
@@ -21,6 +21,7 @@ from eos.db.util import processEager, processWhere
|
||||
from eos.db import saveddata_session, sd_lock
|
||||
from eos.types import User, Character, Fit, Price, DamagePattern, Fleet, MiscData, Wing, Squad
|
||||
from eos.db.saveddata.fleet import squadmembers_table
|
||||
from eos.db.saveddata.fit import projectedFits_table
|
||||
from sqlalchemy.sql import and_
|
||||
import eos.config
|
||||
|
||||
@@ -360,7 +361,15 @@ def getSquadsIDsWithFitID(fitID):
|
||||
return squads
|
||||
else:
|
||||
raise TypeError("Need integer as argument")
|
||||
|
||||
|
||||
def getProjectedFits(fitID):
|
||||
if isinstance(fitID, int):
|
||||
with sd_lock:
|
||||
filter = and_(projectedFits_table.c.sourceID == fitID, Fit.ID == projectedFits_table.c.victimID)
|
||||
fits = saveddata_session.query(Fit).filter(filter).all()
|
||||
return fits
|
||||
else:
|
||||
raise TypeError("Need integer as argument")
|
||||
|
||||
def add(stuff):
|
||||
with sd_lock:
|
||||
|
||||
@@ -162,6 +162,8 @@ class Fit(object):
|
||||
fit = eos.db.getFit(fitID)
|
||||
sFlt = Fleet.getInstance()
|
||||
sFlt.removeAssociatedFleetData(fit)
|
||||
self.removeProjectedData(fitID)
|
||||
|
||||
eos.db.remove(fit)
|
||||
|
||||
def copyFit(self, fitID):
|
||||
@@ -177,7 +179,15 @@ class Fit(object):
|
||||
fit = eos.db.getFit(fitID)
|
||||
fit.clear()
|
||||
return fit
|
||||
|
||||
|
||||
def removeProjectedData(self, fitID):
|
||||
'''Removes projection relation from ships that have fitID as projection. See GitHub issue #90'''
|
||||
fit = eos.db.getFit(fitID)
|
||||
fits = eos.db.getProjectedFits(fitID)
|
||||
|
||||
for projectee in fits:
|
||||
projectee.projectedFits.remove(fit)
|
||||
|
||||
def toggleFactorReload(self, fitID):
|
||||
if fitID is None:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user