From aedd7ce2dea84b929780cab92a3d74a0ded32e4f Mon Sep 17 00:00:00 2001 From: blitzmann Date: Mon, 26 Oct 2015 21:27:54 -0400 Subject: [PATCH] Add support to delete fit from EVE --- gui/crestFittings.py | 27 +++++++++++++++++++++++++-- service/crest.py | 4 ++++ service/pycrest/eve.py | 5 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gui/crestFittings.py b/gui/crestFittings.py index 7602512db..4ddfe4580 100644 --- a/gui/crestFittings.py +++ b/gui/crestFittings.py @@ -50,15 +50,21 @@ class CrestFittings(wx.Frame): fitSizer = wx.BoxSizer( wx.VERTICAL ) self.fitView = FitView(self) - self.importBtn = wx.Button( self, wx.ID_ANY, u"Import", wx.DefaultPosition, wx.DefaultSize, 5 ) fitSizer.Add( self.fitView, 1, wx.ALL|wx.EXPAND, 5 ) - fitSizer.Add( self.importBtn, 0, wx.ALL|wx.EXPAND, 5 ) + + btnSizer = wx.BoxSizer( wx.HORIZONTAL ) + self.importBtn = wx.Button( self, wx.ID_ANY, u"Import to pyfa", wx.DefaultPosition, wx.DefaultSize, 5 ) + self.deleteBtn = wx.Button( self, wx.ID_ANY, u"Delete from EVE", wx.DefaultPosition, wx.DefaultSize, 5 ) + btnSizer.Add( self.importBtn, 1, wx.ALL, 5 ) + btnSizer.Add( self.deleteBtn, 1, wx.ALL, 5 ) + fitSizer.Add( btnSizer, 0, wx.EXPAND ) contentSizer.Add(fitSizer, 1, wx.EXPAND, 0) mainSizer.Add(contentSizer, 1, wx.EXPAND, 5) self.fetchBtn.Bind(wx.EVT_BUTTON, self.fetchFittings) self.importBtn.Bind(wx.EVT_BUTTON, self.importFitting) + self.deleteBtn.Bind(wx.EVT_BUTTON, self.deleteFitting) pub.subscribe(self.ssoLogout, 'logout_success') @@ -119,11 +125,27 @@ class CrestFittings(wx.Frame): def importFitting(self, event): selection = self.fitView.fitSelection + if not selection: + return data = self.fitTree.fittingsTreeCtrl.GetPyData(selection) sFit = service.Fit.getInstance() fits = sFit.importFitFromBuffer(data) self.mainFrame._openAfterImport(fits) + def deleteFitting(self, event): + sCrest = service.Crest.getInstance() + selection = self.fitView.fitSelection + if not selection: + return + data = json.loads(self.fitTree.fittingsTreeCtrl.GetPyData(selection)) + + dlg = wx.MessageDialog(self, + "Do you really want to delete %s (%s) from EVE?"%(data['name'], data['ship']['name']), + "Confirm Delete", wx.YES | wx.NO | wx.ICON_QUESTION) + + if dlg.ShowModal() == wx.ID_YES: + sCrest.delFitting(self.getActiveCharacter(), data['fittingID']) + class ExportToEve(wx.Frame): @@ -337,3 +359,4 @@ class FitView(d.Display): def __init__(self, parent): d.Display.__init__(self, parent, style=wx.LC_SINGLE_SEL) + self.fitSelection = None diff --git a/service/crest.py b/service/crest.py index 8431132f7..b86289d0a 100644 --- a/service/crest.py +++ b/service/crest.py @@ -95,6 +95,10 @@ class Crest(): char = self.getCrestCharacter(charID) return char.eve.post('https://api-sisi.testeveonline.com/characters/%d/fittings/'%char.ID, data=json) + def delFitting(self, charID, fittingID): + char = self.getCrestCharacter(charID) + return char.eve.delete('https://api-sisi.testeveonline.com/characters/%d/fittings/%d/'%(char.ID, fittingID)) + def logout(self): logging.debug("Character logout") self.implicitCharacter = None diff --git a/service/pycrest/eve.py b/service/pycrest/eve.py index b42041f90..55614463d 100644 --- a/service/pycrest/eve.py +++ b/service/pycrest/eve.py @@ -275,6 +275,11 @@ class AuthedConnection(EVE): self.refr_authorize(self.refresh_token) return self._session.post(resource, data=data, params=params) + def delete(self, resource, params=None): + if self.refresh_token and int(time.time()) >= self.expires: + self.refr_authorize(self.refresh_token) + return self._session.delete(resource, params=params) + class APIObject(object): def __init__(self, parent, connection): self._dict = {}