Compare commits

..

1 Commits

Author SHA1 Message Date
Peter Pfeufer
168028ab3b Merge branch 'user-menu-fixes' into 'master'
User Menu Template Fixes

See merge request allianceauth/allianceauth!1728
2025-06-15 10:16:35 +00:00
3 changed files with 13 additions and 32 deletions

View File

@ -10,39 +10,24 @@ from allianceauth.authentication.models import CharacterOwnership
from allianceauth.eveonline.models import EveCharacter from allianceauth.eveonline.models import EveCharacter
def get_all_characters_from_user(user: User, main_first: bool = False) -> list: def get_all_characters_from_user(user: User) -> list:
""" """
Get all characters from a user Get all characters from a user or an empty list
This function retrieves all characters associated with a given user, optionally ordering them when no characters are found for the user or the user is None
with the main character first.
If the user is None, an empty list is returned.
:param user: The user whose characters are to be retrieved :param user:
:type user: User :type user:
:param main_first: If True, the main character will be listed first :return:
:type main_first: bool :rtype:
:return: A list of EveCharacter objects associated with the user
:rtype: list[EveCharacter]
""" """
if user is None: if user is None:
return [] return []
try: try:
if main_first: characters = [
characters = [ char.character for char in CharacterOwnership.objects.filter(user=user)
char.character ]
for char in CharacterOwnership.objects.filter(user=user).order_by(
"-character__userprofile", "character__character_name"
)
]
else:
characters = [
char.character
for char in CharacterOwnership.objects.filter(user=user).order_by(
"character__character_name"
)
]
except AttributeError: except AttributeError:
return [] return []

View File

@ -675,7 +675,7 @@ class DiscordClient:
) )
logger.debug('%s: response:\n%s', uid, r.text) logger.debug('%s: response:\n%s', uid, r.text)
if not r.ok: if not r.ok:
logger.error( logger.warning(
'%s: Discord API returned error code %d and this response: %s', '%s: Discord API returned error code %d and this response: %s',
uid, uid,
r.status_code, r.status_code,

View File

@ -43,7 +43,7 @@ if the `EveCharacter` has no user.
### get_all_characters_from_user ### get_all_characters_from_user
This is to get all character objects (`EveCharacter`) of a user (alphabetically sorted). This is to get all character objects (`EveCharacter`) of a user.
Given we have a `User` object called `my_user` and we want to get all characters: Given we have a `User` object called `my_user` and we want to get all characters:
@ -51,16 +51,12 @@ Given we have a `User` object called `my_user` and we want to get all characters
# Alliance Auth # Alliance Auth
from allianceauth.framework.api.user import get_all_characters_from_user from allianceauth.framework.api.user import get_all_characters_from_user
characters = get_all_characters_from_user(user=my_user, main_first=False) characters = get_all_characters_from_user(user=my_user)
``` ```
Now, `characters` is a `list` containing all `EveCharacter` objects of the user. Now, `characters` is a `list` containing all `EveCharacter` objects of the user.
If the user is `None`, an empty `list` will be returned. If the user is `None`, an empty `list` will be returned.
The second parameter `main_first` is optional and defaults to `False`.
If set to `True`, the function will return the main character as the first
item in the list of characters.
### get_main_character_from_user ### get_main_character_from_user
This is to get the main character object (`EveCharacter`) of a user. This is to get the main character object (`EveCharacter`) of a user.