mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-16 16:00:17 +02:00
Add tooltips to users, add CSS
This commit is contained in:
parent
ab061ba7a6
commit
9d0a65a516
@ -18,6 +18,7 @@ from allianceauth.authentication.models import State, get_guest_state,\
|
|||||||
CharacterOwnership, UserProfile, OwnershipRecord
|
CharacterOwnership, UserProfile, OwnershipRecord
|
||||||
from allianceauth.hooks import get_hooks
|
from allianceauth.hooks import get_hooks
|
||||||
from allianceauth.eveonline.models import EveCharacter, EveCorporationInfo
|
from allianceauth.eveonline.models import EveCharacter, EveCorporationInfo
|
||||||
|
from allianceauth.eveonline.tasks import update_character
|
||||||
|
|
||||||
if 'allianceauth.eveonline.autogroups' in settings.INSTALLED_APPS:
|
if 'allianceauth.eveonline.autogroups' in settings.INSTALLED_APPS:
|
||||||
_has_auto_groups = True
|
_has_auto_groups = True
|
||||||
@ -26,6 +27,10 @@ else:
|
|||||||
_has_auto_groups = False
|
_has_auto_groups = False
|
||||||
|
|
||||||
|
|
||||||
|
_USERS_MAX_GROUPS = 5
|
||||||
|
_USERS_MAX_CHARACTERS = 3
|
||||||
|
|
||||||
|
|
||||||
def make_service_hooks_update_groups_action(service):
|
def make_service_hooks_update_groups_action(service):
|
||||||
"""
|
"""
|
||||||
Make a admin action for the given service
|
Make a admin action for the given service
|
||||||
@ -164,13 +169,54 @@ class MainAllianceFilter(admin.SimpleListFilter):
|
|||||||
.filter(profile__main_character__alliance_id=self.value())
|
.filter(profile__main_character__alliance_id=self.value())
|
||||||
|
|
||||||
|
|
||||||
|
def update_main_character_model(modeladmin, request, queryset):
|
||||||
|
tasks_count = 0
|
||||||
|
for obj in queryset:
|
||||||
|
if obj.profile.main_character:
|
||||||
|
update_character.delay(obj.profile.main_character.character_id)
|
||||||
|
tasks_count += 1
|
||||||
|
|
||||||
|
modeladmin.message_user(
|
||||||
|
request,
|
||||||
|
'Update from ESI started for {} characters'.format(tasks_count)
|
||||||
|
)
|
||||||
|
|
||||||
|
update_main_character_model.short_description = \
|
||||||
|
'Update main character model from ESI'
|
||||||
|
|
||||||
|
def list_2_html_w_tooltips(my_items: list, max_items: int) -> str:
|
||||||
|
"""converts list of strings into HTML with cutoff and tooltip when > max"""
|
||||||
|
items_truncated_str = ', '.join(my_items[:max_items])
|
||||||
|
if len(my_items) <= max_items:
|
||||||
|
return items_truncated_str
|
||||||
|
else:
|
||||||
|
items_truncated_str += ' (...)'
|
||||||
|
items_all_str = ', '.join(my_items)
|
||||||
|
return format_html(
|
||||||
|
'<span data-tooltip="{}" class="tooltip">{}</span>',
|
||||||
|
items_all_str,
|
||||||
|
items_truncated_str
|
||||||
|
)
|
||||||
|
|
||||||
class UserAdmin(BaseUserAdmin):
|
class UserAdmin(BaseUserAdmin):
|
||||||
"""
|
"""
|
||||||
Extending Django's UserAdmin model
|
Extending Django's UserAdmin model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class Media:
|
||||||
|
css = {
|
||||||
|
"all": ("authentication/css/admin.css",)
|
||||||
|
}
|
||||||
|
|
||||||
def get_actions(self, request):
|
def get_actions(self, request):
|
||||||
actions = super(BaseUserAdmin, self).get_actions(request)
|
actions = super(BaseUserAdmin, self).get_actions(request)
|
||||||
|
|
||||||
|
actions[update_main_character_model.__name__] = (
|
||||||
|
update_main_character_model,
|
||||||
|
update_main_character_model.__name__,
|
||||||
|
update_main_character_model.short_description
|
||||||
|
)
|
||||||
|
|
||||||
for hook in get_hooks('services_hook'):
|
for hook in get_hooks('services_hook'):
|
||||||
svc = hook()
|
svc = hook()
|
||||||
# Check update_groups is redefined/overloaded
|
# Check update_groups is redefined/overloaded
|
||||||
@ -210,9 +256,7 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
list_filter = (
|
list_filter = (
|
||||||
'profile__state',
|
'profile__state',
|
||||||
RealGroupsFilter,
|
RealGroupsFilter,
|
||||||
#'profile__main_character__corporation_name',
|
|
||||||
MainCorporationsFilter,
|
MainCorporationsFilter,
|
||||||
#'profile__main_character__alliance_name',
|
|
||||||
MainAllianceFilter,
|
MainAllianceFilter,
|
||||||
'is_active',
|
'is_active',
|
||||||
'date_joined',
|
'date_joined',
|
||||||
@ -221,14 +265,13 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
)
|
)
|
||||||
search_fields = (
|
search_fields = (
|
||||||
'username',
|
'username',
|
||||||
'character_ownerships__character__character_name',
|
'character_ownerships__character__character_name'
|
||||||
'groups__name'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _profile_pic(self, obj):
|
def _profile_pic(self, obj):
|
||||||
if obj.profile.main_character:
|
if obj.profile.main_character:
|
||||||
return format_html(
|
return format_html(
|
||||||
'<img src="{}" style="border-radius: 50%;">',
|
'<img src="{}" class="img-circle">',
|
||||||
obj.profile.main_character.portrait_url(size=32)
|
obj.profile.main_character.portrait_url(size=32)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -275,12 +318,13 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
|
|
||||||
|
|
||||||
def _characters(self, obj):
|
def _characters(self, obj):
|
||||||
return [
|
my_characters = [
|
||||||
x.character.character_name
|
x.character.character_name
|
||||||
for x in CharacterOwnership.objects\
|
for x in CharacterOwnership.objects\
|
||||||
.filter(user=obj)\
|
.filter(user=obj)\
|
||||||
.order_by('character__character_name')
|
.order_by('character__character_name')
|
||||||
]
|
]
|
||||||
|
return list_2_html_w_tooltips(my_characters, _USERS_MAX_CHARACTERS)
|
||||||
|
|
||||||
_characters.short_description = 'characters'
|
_characters.short_description = 'characters'
|
||||||
|
|
||||||
@ -303,7 +347,7 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
.order_by('name')
|
.order_by('name')
|
||||||
]
|
]
|
||||||
|
|
||||||
return ', '.join(my_groups)
|
return list_2_html_w_tooltips(my_groups, _USERS_MAX_GROUPS)
|
||||||
|
|
||||||
_groups.short_description = 'groups'
|
_groups.short_description = 'groups'
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
CSS for allianceauth admin site
|
||||||
|
*/
|
||||||
|
|
||||||
|
.img-circle { border-radius: 50%; }
|
||||||
|
.column-_profile_pic { width: 50px; }
|
||||||
|
|
||||||
|
/* tooltip */
|
||||||
|
.tooltip {
|
||||||
|
position: relative ;
|
||||||
|
}
|
||||||
|
.tooltip:hover::after {
|
||||||
|
content: attr(data-tooltip) ;
|
||||||
|
position: absolute ;
|
||||||
|
top: 1.1em ;
|
||||||
|
left: 1em ;
|
||||||
|
min-width: 200px ;
|
||||||
|
border: 1px #808080 solid ;
|
||||||
|
padding: 8px ;
|
||||||
|
color: black ;
|
||||||
|
background-color: rgb(255, 255, 204) ;
|
||||||
|
z-index: 1 ;
|
||||||
|
}
|
@ -15,7 +15,6 @@ class MainCorporationsFilter(admin.SimpleListFilter):
|
|||||||
def lookups(self, request, model_admin):
|
def lookups(self, request, model_admin):
|
||||||
qs = EveCharacter.objects\
|
qs = EveCharacter.objects\
|
||||||
.exclude(userprofile=None)\
|
.exclude(userprofile=None)\
|
||||||
.exclude(userprofile__user__discord=None)\
|
|
||||||
.values('corporation_id', 'corporation_name')\
|
.values('corporation_id', 'corporation_name')\
|
||||||
.distinct()\
|
.distinct()\
|
||||||
.order_by(Lower('corporation_name'))
|
.order_by(Lower('corporation_name'))
|
||||||
@ -40,7 +39,6 @@ class MainAllianceFilter(admin.SimpleListFilter):
|
|||||||
qs = EveCharacter.objects\
|
qs = EveCharacter.objects\
|
||||||
.exclude(alliance_id=None)\
|
.exclude(alliance_id=None)\
|
||||||
.exclude(userprofile=None)\
|
.exclude(userprofile=None)\
|
||||||
.exclude(userprofile__user__discord=None)\
|
|
||||||
.values('alliance_id', 'alliance_name')\
|
.values('alliance_id', 'alliance_name')\
|
||||||
.distinct()\
|
.distinct()\
|
||||||
.order_by(Lower('alliance_name'))
|
.order_by(Lower('alliance_name'))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
CSS for allianceauth services admin site
|
CSS for allianceauth admin site
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.img-circle { border-radius: 50%; }
|
.img-circle { border-radius: 50%; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user