Compare commits

..

1 Commits

Author SHA1 Message Date
Peter Pfeufer
6e3ef36ae9 Merge branch 'exclude-biomassed-characters' into 'master'
[ADD] `exclude_biomassed` to `EveCharacterManager`

See merge request allianceauth/allianceauth!1727
2025-06-13 09:32:02 +00:00
6 changed files with 59 additions and 157 deletions

View File

@ -1,6 +1,7 @@
{% load i18n %} {% load i18n %}
<form class="dropdown-item" action="{% url 'set_language' %}" method="post"> <div class="dropdown">
<form action="{% url 'set_language' %}" method="post">
{% csrf_token %} {% csrf_token %}
<select class="form-select" onchange="this.form.submit()" class="form-control" id="lang-select" name="language"> <select class="form-select" onchange="this.form.submit()" class="form-control" id="lang-select" name="language">
@ -12,4 +13,5 @@
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
</form> </form>
</div>

View File

@ -10,38 +10,23 @@ 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 char.character for char in CharacterOwnership.objects.filter(user=user)
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

@ -2,51 +2,28 @@
{% load evelinks %} {% load evelinks %}
{% load theme_tags %} {% load theme_tags %}
<div <div id="aa-user-info" class="w-100 d-flex flex-column justify-content-center align-items-center text-center py-1 border-top border-secondary {% if not user.is_authenticated %}position-absolute bottom-0{% endif %}">
id="aa-user-info"
class="w-100 d-flex flex-column justify-content-center align-items-center text-center py-1 border-top border-secondary {% if not user.is_authenticated %}position-absolute bottom-0{% endif %}"
>
<div class="d-flex mb-0 w-100"> <div class="d-flex mb-0 w-100">
<div class="p-2 position-relative m-2"> <div class="p-2 position-relative m-2">
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% with request.user.profile.main_character as main %} {% with request.user.profile.main_character as main %}
<img <img class="rounded-circle" src="{{ main.character_id|character_portrait_url:64 }}" alt="{{ main.character_name }}">
class="rounded-circle" <img class="rounded-circle position-absolute bottom-0 start-0" src="{{ main.corporation_logo_url_32 }}" alt="{{ main.corporation_name }}">
src="{{ main.character_id|character_portrait_url:64 }}"
alt="{{ main.character_name }}"
>
<img
class="rounded-circle position-absolute bottom-0 start-0"
src="{{ main.corporation_logo_url_32 }}"
alt="{{ main.corporation_name }}"
>
{% if main.alliance_id %} {% if main.alliance_id %}
<img <img class="rounded-circle position-absolute bottom-0 end-0" src="{{ main.alliance_logo_url_32 }}" alt="{{ main.alliance_name }}">
class="rounded-circle position-absolute bottom-0 end-0"
src="{{ main.alliance_logo_url_32 }}"
alt="{{ main.alliance_name }}"
>
{% elif main.faction_id %} {% elif main.faction_id %}
<img <img class="rounded-circle position-absolute bottom-0 end-0" src="{{ main.faction_logo_url_32 }}" alt="{{ main.faction_name }}">
class="rounded-circle position-absolute bottom-0 end-0"
src="{{ main.faction_logo_url_32 }}"
alt="{{ main.faction_name }}"
>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% else %} {% else %}
{% include "bundles/image-auth-logo.html" with logo_width="64px" %} {% include "bundles/image-auth-logo.html" with logo_width="64px" %}
{% endif %} {% endif %}
</div> </div>
<div class="align-self-center text-start"> <div class="align-self-center text-start">
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% with request.user.profile.main_character as main %} {% with request.user.profile.main_character as main %}
<h5 class="m-0">{{ main.character_name }}</h5> <h5 class="m-0">{{ main.character_name }}</h5>
<p class="m-0 small">{{ main.corporation_name }}</p> <p class="m-0 small">{{ main.corporation_name }}</p>
{% if main.alliance_id %} {% if main.alliance_id %}
<p class="m-0 small">{{ main.alliance_name }}</p> <p class="m-0 small">{{ main.alliance_name }}</p>
{% elif main.faction_id %} {% elif main.faction_id %}
@ -57,106 +34,56 @@
<h5 class="m-0">{{ SITE_NAME }}</h5> <h5 class="m-0">{{ SITE_NAME }}</h5>
{% endif %} {% endif %}
</div> </div>
<div class="ms-auto dropup"> <div class="ms-auto dropup">
<button type="button" class="h-100 btn" data-bs-toggle="dropdown" aria-expanded="false"> <button type="button" class="h-100 btn" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fa-solid fa-gear fa-fw text-light"></i> <i class="fa-solid fa-gear fa-fw text-light"></i>
</button> </button>
<ul class="dropdown-menu" style="min-width: 200px;"> <ul class="dropdown-menu" style="min-width: 200px;">
<li><h6 class="dropdown-header">{% translate "Language" %}</h6></li> <li><h6 class="dropdown-header">{% translate "Language" %}</h6></li>
<li>
<a class="dropdown-item">{% include "public/lang_select.html" %}</a>
</li>
<li><h6 class="dropdown-header">{% translate "Theme" %}</h6></li>
<li> <li>
{% include "public/lang_select.html" %} <a class="dropdown-item">
</li>
{% theme_select %} {% theme_select %}
</a>
</li>
{% if user.is_superuser %} {% if user.is_superuser %}
<li><hr class="dropdown-divider"></li> <li><hr class="dropdown-divider"></li>
<li><h6 class="dropdown-header">{% translate "Super User" %}</h6></li> <li><h6 class="dropdown-header">{% translate "Super User" %}</h6></li>
<li> <li>
<a <a class="dropdown-item" href="https://allianceauth.readthedocs.io/" title="Alliance Auth Documentation"><i class="fa-solid fa-book fa-fw"></i> Alliance Auth Documentation</a>
class="dropdown-item"
href="https://allianceauth.readthedocs.io/"
title="{% translate 'Alliance Auth Documentation' %}"
>
<i class="fa-solid fa-book fa-fw"></i>
{% translate "Alliance Auth Documentation" %}
</a>
</li> </li>
<li> <li>
<a <a class="dropdown-item" href="https://discord.gg/fjnHAmk" title="Alliance Auth Discord"><i class="fa-brands fa-discord fa-fw"></i> Alliance Auth Discord</a>
class="dropdown-item"
href="https://discord.gg/fjnHAmk"
title="{% translate 'Alliance Auth Discord' %}"
>
<i class="fa-brands fa-discord fa-fw"></i>
{% translate "Alliance Auth Discord" %}
</a>
</li> </li>
<li> <li>
<a <a class="dropdown-item" href="https://gitlab.com/allianceauth/allianceauth" title="Alliance Auth Git"><i class="fa-brands fa-gitlab fa-fw"></i> Alliance Auth Git</a>
class="dropdown-item"
href="https://gitlab.com/allianceauth/allianceauth"
title="{% translate 'Alliance Auth Git' %}"
>
<i class="fa-brands fa-gitlab fa-fw"></i>
{% translate "Alliance Auth Git" %}
</a>
</li> </li>
{% endif %} {% endif %}
{% if user.is_staff %} {% if user.is_staff %}
<li> <li>
<a <a class="dropdown-item" href="{% url 'admin:index' %}">
class="dropdown-item" <i class="fa-solid fa-gear fa-fw"></i> {% translate "Admin" %}
href="{% url 'admin:index' %}"
title="{% translate 'Admin' %}"
>
<i class="fa-solid fa-gear fa-fw"></i>
{% translate "Admin" %}
</a> </a>
</li> </li>
{% endif %} {% endif %}
<li><hr class="dropdown-divider"></li> <li><hr class="dropdown-divider"></li>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li> <li>
<a <a class="dropdown-item" href="{% url 'authentication:token_management' %}">
class="dropdown-item" <i class="fa-solid fa-user-lock fa-fw"></i> Token Management
href="{% url 'authentication:token_management' %}"
title="{% translate 'Token Management' %}"
>
<i class="fa-solid fa-user-lock fa-fw"></i>
{% translate "Token Management" %}
</a> </a>
</li> </li>
<li> <li>
<a <a class="dropdown-item text-danger" href="{% url 'logout' %}" title="{% translate 'Sign Out' %}"><i class="fa-solid fa-right-from-bracket fa-fw "></i> {% translate 'Sign Out' %}</a>
class="dropdown-item text-danger"
href="{% url 'logout' %}"
title="{% translate 'Sign Out' %}"
>
<i class="fa-solid fa-right-from-bracket fa-fw"></i>
{% translate 'Sign Out' %}
</a>
</li> </li>
{% else %} {% else %}
<li> <li>
<a <a class="dropdown-item text-success" href="{% url 'authentication:login' %}" title="{% translate 'Sign In' %}"> <i class="fa-solid fa-right-to-bracket fa-fw "></i> {% translate 'Sign In' %}</a>
class="dropdown-item text-success"
href="{% url 'authentication:login' %}"
title="{% translate 'Sign In' %}"
>
<i class="fa-solid fa-right-to-bracket fa-fw"></i>
{% translate 'Sign In' %}
</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>

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

@ -1,21 +1,13 @@
{% load i18n %} {% load i18n %}
{% if themes|length > 1 %} <form action="{% url 'theme' %}?next={{ next|urlencode }}" method="post">
<li><h6 class="dropdown-header">{% translate "Theme" %}</h6></li>
<li>
<form class="dropdown-item" action="{% url 'theme' %}?next={{ next|urlencode }}" method="post">
{% csrf_token %} {% csrf_token %}
<select name="theme" class="form-select" onchange="this.form.submit()"> <select name="theme" class="form-select" aria-label="" onchange="this.form.submit()">
<option selected>{% translate "Select Theme" %}</option> <option selected>{% translate "Select Theme" %}</option>
{% for theme in themes %} {% for theme in themes %}
<option value="{{ theme.get_name }}"{% if selected_theme.name == theme.name %} selected="selected"{% endif %}> <option value="{{ theme.get_name }}"{% if selected_theme.name == theme.name %} selected="selected"{% endif %}>{{ theme.name }}</option>
{{ theme.name }}
</option>
{% endfor %} {% endfor %}
</select> </select>
</form> </form>
</li>
{% endif %}

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.