mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-12 10:06:21 +01:00
Making it pretty
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import evelink.api # Raw API access
|
||||
import evelink.char # Wrapped API access for the /char/ API path
|
||||
import evelink.eve # Wrapped API access for the /eve/ API path
|
||||
|
||||
from models import EveCharacter
|
||||
|
||||
|
||||
class EveCharacterManager():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def create_character(self,character_id, character_name,corporation_id,
|
||||
def create_character(self, character_id, character_name, corporation_id,
|
||||
corporation_name, alliance_id,
|
||||
alliance_name, allianceuser_owner):
|
||||
|
||||
@@ -23,7 +20,19 @@ class EveCharacterManager():
|
||||
eve_char.allianceuser_owner = allianceuser_owner
|
||||
|
||||
eve_char.save()
|
||||
|
||||
|
||||
def create_characters_from_list(self, chars, owner):
|
||||
for char in chars.result:
|
||||
if not self.check_if_character_exist(chars.result[char]['name']):
|
||||
self.create_character(chars.result[char]['id'],
|
||||
chars.result[char]['name'],
|
||||
chars.result[char]['corp']['id'], chars.result[char]['corp']['name'],
|
||||
chars.result[char]['alliance']['id'], chars.result[char]['alliance']['name'],
|
||||
owner)
|
||||
|
||||
def check_if_character_exist(self, char_name):
|
||||
return EveCharacter.objects.filter(character_name=char_name).exists()
|
||||
|
||||
def get_characters_by_owner_id(self, owner_id):
|
||||
return EveCharacter.objects.all().filter(allianceuser_owner=owner_id)
|
||||
|
||||
@@ -39,36 +48,4 @@ class EveCharacterManager():
|
||||
if character.allianceuser_owner.id == user_id:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
class EveApiManager():
|
||||
|
||||
characterManager = EveCharacterManager()
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def CreateCharactersFromID(self,api_id, api_key, user):
|
||||
# Create user
|
||||
api = evelink.api.API(api_key=(api_id, api_key))
|
||||
# Should get characters
|
||||
account = evelink.account.Account(api=api)
|
||||
chars = account.characters()
|
||||
|
||||
# Have our characters now lets populate database
|
||||
for char in chars.result:
|
||||
self.characterManager.create_character( chars.result[char]['id'], chars.result[char]['name'],
|
||||
chars.result[char]['corp']['id'], chars.result[char]['corp']['name'],
|
||||
chars.result[char]['alliance']['id'],chars.result[char]['alliance']['name'],
|
||||
user)
|
||||
#Done
|
||||
|
||||
def GetCorpNameByKey(self, api_id, api_key):
|
||||
pass
|
||||
|
||||
def GetAllianceNameByKey(self, api_id, api_key):
|
||||
pass
|
||||
|
||||
def GetCharactersByKey(self, api_id, api_key):
|
||||
pass
|
||||
|
||||
return False
|
||||
@@ -2,12 +2,12 @@ from django.db import models
|
||||
|
||||
from authentication.models import AllianceUser
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class EveCharacter(models.Model):
|
||||
character_id = models.CharField(max_length=254)
|
||||
character_name = models.CharField(max_length=254)
|
||||
corporation_id = models.CharField(max_length=254)
|
||||
corporation_name = models.CharField(max_length=254)
|
||||
alliance_id = models.CharField(max_length=254)
|
||||
alliance_name = models.CharField(max_length=254)
|
||||
character_id = models.CharField(max_length=254)
|
||||
character_name = models.CharField(max_length=254)
|
||||
corporation_id = models.CharField(max_length=254)
|
||||
corporation_name = models.CharField(max_length=254)
|
||||
alliance_id = models.CharField(max_length=254)
|
||||
alliance_name = models.CharField(max_length=254)
|
||||
allianceuser_owner = models.ForeignKey(AllianceUser)
|
||||
Reference in New Issue
Block a user