mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-12 18:16:24 +01:00
Allow assigning factions to states.
This commit is contained in:
@@ -22,6 +22,7 @@ get_corporations_corporation_id
|
||||
get_characters_character_id
|
||||
get_universe_types_type_id
|
||||
post_character_affiliation
|
||||
get_universe_factions
|
||||
"""
|
||||
|
||||
|
||||
@@ -38,7 +39,8 @@ class ObjectNotFound(Exception):
|
||||
|
||||
|
||||
class Entity:
|
||||
def __init__(self, id=None, name=None):
|
||||
def __init__(self, id=None, name=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
@@ -55,15 +57,11 @@ class Entity:
|
||||
return self.id == other.id
|
||||
|
||||
|
||||
class Corporation(Entity):
|
||||
def __init__(self, ticker=None, ceo_id=None, members=None, alliance_id=None, **kwargs):
|
||||
class AllianceMixin:
|
||||
def __init__(self, alliance_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
self.ceo_id = ceo_id
|
||||
self.members = members
|
||||
self.alliance_id = alliance_id
|
||||
self._alliance = None
|
||||
self._ceo = None
|
||||
|
||||
@property
|
||||
def alliance(self):
|
||||
@@ -73,6 +71,30 @@ class Corporation(Entity):
|
||||
return self._alliance
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class FactionMixin:
|
||||
def __init__(self, faction_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.faction_id = faction_id
|
||||
self._faction = None
|
||||
|
||||
@property
|
||||
def faction(self):
|
||||
if self.faction_id:
|
||||
if not self._faction:
|
||||
self._faction = provider.get_faction(self.faction_id)
|
||||
return self._faction
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class Corporation(Entity, AllianceMixin, FactionMixin):
|
||||
def __init__(self, ticker=None, ceo_id=None, members=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
self.ceo_id = ceo_id
|
||||
self.members = members
|
||||
self._ceo = None
|
||||
|
||||
@property
|
||||
def ceo(self):
|
||||
if not self._ceo:
|
||||
@@ -80,7 +102,7 @@ class Corporation(Entity):
|
||||
return self._ceo
|
||||
|
||||
|
||||
class Alliance(Entity):
|
||||
class Alliance(Entity, FactionMixin):
|
||||
def __init__(self, ticker=None, corp_ids=None, executor_corp_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.ticker = ticker
|
||||
@@ -106,13 +128,11 @@ class Alliance(Entity):
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class Character(Entity):
|
||||
def __init__(self, corp_id=None, alliance_id=None, **kwargs):
|
||||
class Character(Entity, AllianceMixin, FactionMixin):
|
||||
def __init__(self, corp_id=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.corp_id = corp_id
|
||||
self.alliance_id = alliance_id
|
||||
self._corp = None
|
||||
self._alliance = None
|
||||
|
||||
@property
|
||||
def corp(self):
|
||||
@@ -120,12 +140,6 @@ class Character(Entity):
|
||||
self._corp = provider.get_corp(self.corp_id)
|
||||
return self._corp
|
||||
|
||||
@property
|
||||
def alliance(self):
|
||||
if self.alliance_id:
|
||||
return self.corp.alliance
|
||||
return Entity(None, None)
|
||||
|
||||
|
||||
class ItemType(Entity):
|
||||
def __init__(self, **kwargs):
|
||||
@@ -179,6 +193,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
|
||||
self._token = token
|
||||
self.adapter = adapter or self
|
||||
self._faction_list = None # what are the odds this will change? could cache forever!
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
@@ -201,6 +216,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
ticker=data['ticker'],
|
||||
corp_ids=corps,
|
||||
executor_corp_id=data['executor_corporation_id'] if 'executor_corporation_id' in data else None,
|
||||
faction_id=data['faction_id'] if 'faction_id' in data else None,
|
||||
)
|
||||
return model
|
||||
except HTTPNotFound:
|
||||
@@ -216,6 +232,7 @@ class EveSwaggerProvider(EveProvider):
|
||||
ceo_id=data['ceo_id'],
|
||||
members=data['member_count'],
|
||||
alliance_id=data['alliance_id'] if 'alliance_id' in data else None,
|
||||
faction_id=data['faction_id'] if 'faction_id' in data else None,
|
||||
)
|
||||
return model
|
||||
except HTTPNotFound:
|
||||
@@ -231,11 +248,30 @@ class EveSwaggerProvider(EveProvider):
|
||||
name=data['name'],
|
||||
corp_id=affiliation['corporation_id'],
|
||||
alliance_id=affiliation['alliance_id'] if 'alliance_id' in affiliation else None,
|
||||
faction_id=affiliation['faction_id'] if 'faction_id' in affiliation else None,
|
||||
)
|
||||
return model
|
||||
except (HTTPNotFound, HTTPUnprocessableEntity):
|
||||
raise ObjectNotFound(character_id, 'character')
|
||||
|
||||
def get_all_factions(self):
|
||||
if not self._faction_list:
|
||||
self._faction_list = self.client.Universe.get_universe_factions().result()
|
||||
return self._faction_list
|
||||
|
||||
def get_faction(self, faction_id):
|
||||
faction_id=int(faction_id)
|
||||
try:
|
||||
if not self._faction_list:
|
||||
_ = self.get_all_factions()
|
||||
for f in self._faction_list:
|
||||
if f['faction_id'] == faction_id:
|
||||
return Entity(id=f['faction_id'], name=f['name'])
|
||||
else:
|
||||
raise KeyError()
|
||||
except (HTTPNotFound, HTTPUnprocessableEntity, KeyError):
|
||||
raise ObjectNotFound(faction_id, 'faction')
|
||||
|
||||
def get_itemtype(self, type_id):
|
||||
try:
|
||||
data = self.client.Universe.get_universe_types_type_id(type_id=type_id).result()
|
||||
|
||||
Reference in New Issue
Block a user