mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-05 06:36:19 +01:00
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
"""
|
|
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
|