mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-09 00:26:20 +01:00
[ADD] Evecharacter API functions
This commit is contained in:
57
allianceauth/framework/api/evecharacter.py
Normal file
57
allianceauth/framework/api/evecharacter.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
Alliance Auth Evecharacter API
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from allianceauth.authentication.models import CharacterOwnership
|
||||
from allianceauth.eveonline.models import EveCharacter
|
||||
from allianceauth.framework.api.user import get_sentinel_user
|
||||
|
||||
|
||||
def get_main_character_from_evecharacter(
|
||||
character: EveCharacter,
|
||||
) -> Optional[EveCharacter]:
|
||||
"""
|
||||
Get the main character for a given Evecharacter or None when no main character is set
|
||||
|
||||
:param character:
|
||||
:type character:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
try:
|
||||
userprofile = character.character_ownership.user.profile
|
||||
except (
|
||||
AttributeError,
|
||||
EveCharacter.character_ownership.RelatedObjectDoesNotExist,
|
||||
CharacterOwnership.user.RelatedObjectDoesNotExist,
|
||||
):
|
||||
return None
|
||||
|
||||
return userprofile.main_character
|
||||
|
||||
|
||||
def get_user_from_evecharacter(character: EveCharacter) -> User:
|
||||
"""
|
||||
Get the user for an Evecharacter or the sentinel user when no user is found
|
||||
|
||||
:param character:
|
||||
:type character:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
try:
|
||||
userprofile = character.character_ownership.user.profile
|
||||
except (
|
||||
AttributeError,
|
||||
EveCharacter.character_ownership.RelatedObjectDoesNotExist,
|
||||
CharacterOwnership.user.RelatedObjectDoesNotExist,
|
||||
):
|
||||
return get_sentinel_user()
|
||||
|
||||
return userprofile.user
|
||||
Reference in New Issue
Block a user