mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 15:30:16 +02:00
Improve user and group admin
This commit is contained in:
parent
564a25e578
commit
2b8bfbe544
@ -106,14 +106,45 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
action.short_description)
|
action.short_description)
|
||||||
|
|
||||||
return actions
|
return actions
|
||||||
list_filter = BaseUserAdmin.list_filter + ('profile__state',)
|
|
||||||
inlines = BaseUserAdmin.inlines + [UserProfileInline]
|
inlines = BaseUserAdmin.inlines + [UserProfileInline]
|
||||||
list_display = ('username', 'email', 'get_main_character', 'get_state', 'is_active')
|
|
||||||
|
list_select_related = True
|
||||||
|
|
||||||
|
list_filter = BaseUserAdmin.list_filter + (
|
||||||
|
'profile__main_character__corporation_name',
|
||||||
|
'profile__main_character__alliance_name',
|
||||||
|
'profile__state',
|
||||||
|
'date_joined'
|
||||||
|
)
|
||||||
|
|
||||||
|
list_display = (
|
||||||
|
'username',
|
||||||
|
'get_main_character',
|
||||||
|
'get_main_corporation',
|
||||||
|
'get_main_alliance',
|
||||||
|
'get_state',
|
||||||
|
'date_joined',
|
||||||
|
'is_active'
|
||||||
|
)
|
||||||
|
|
||||||
def get_main_character(self, obj):
|
def get_main_character(self, obj):
|
||||||
return obj.profile.main_character
|
return obj.profile.main_character
|
||||||
get_main_character.short_description = "Main Character"
|
get_main_character.short_description = "Main Character"
|
||||||
|
|
||||||
|
def get_main_corporation(self, obj):
|
||||||
|
if obj.profile.main_character:
|
||||||
|
return obj.profile.main_character.corporation_name
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
get_main_corporation.short_description = "Main Corporation"
|
||||||
|
|
||||||
|
def get_main_alliance(self, obj):
|
||||||
|
if obj.profile.main_character:
|
||||||
|
return obj.profile.main_character.alliance_name
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
get_main_alliance.short_description = "Main Alliance"
|
||||||
|
|
||||||
def get_state(self, obj):
|
def get_state(self, obj):
|
||||||
return obj.profile.state
|
return obj.profile.state
|
||||||
get_state.short_description = "State"
|
get_state.short_description = "State"
|
||||||
|
@ -1,11 +1,23 @@
|
|||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.models import Group as BaseGroup
|
from django.contrib.auth.models import Group as BaseGroup
|
||||||
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
|
from django.db.models import Count
|
||||||
|
from django.db.models.signals import pre_save, post_save, pre_delete, \
|
||||||
|
post_delete, m2m_changed
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from .models import AuthGroup
|
from .models import AuthGroup
|
||||||
from .models import GroupRequest
|
from .models import GroupRequest
|
||||||
from . import signals
|
from . import signals
|
||||||
|
|
||||||
|
if 'allianceauth.eveonline.autogroups' in settings.INSTALLED_APPS:
|
||||||
|
_has_auto_groups = True
|
||||||
|
from allianceauth.eveonline.autogroups.models import *
|
||||||
|
else:
|
||||||
|
_has_auto_groups = False
|
||||||
|
|
||||||
|
|
||||||
class AuthGroupInlineAdmin(admin.StackedInline):
|
class AuthGroupInlineAdmin(admin.StackedInline):
|
||||||
model = AuthGroup
|
model = AuthGroup
|
||||||
filter_horizontal = ('group_leaders', 'group_leader_groups', 'states',)
|
filter_horizontal = ('group_leaders', 'group_leader_groups', 'states',)
|
||||||
@ -23,10 +35,92 @@ class AuthGroupInlineAdmin(admin.StackedInline):
|
|||||||
return request.user.has_perm('auth.change_group')
|
return request.user.has_perm('auth.change_group')
|
||||||
|
|
||||||
|
|
||||||
|
if _has_auto_groups:
|
||||||
|
class IsAutoGroupFilter(admin.SimpleListFilter):
|
||||||
|
title = 'auto group'
|
||||||
|
parameter_name = 'auto_group'
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return (
|
||||||
|
('Yes', 'Yes'),
|
||||||
|
('No', 'No'),
|
||||||
|
)
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
value = self.value()
|
||||||
|
if value == 'Yes':
|
||||||
|
return queryset.exclude(
|
||||||
|
managedalliancegroup__exact=None,
|
||||||
|
managedcorpgroup__exact=None
|
||||||
|
)
|
||||||
|
elif value == 'No':
|
||||||
|
return queryset.filter(managedalliancegroup__exact=None).filter(managedcorpgroup__exact=None)
|
||||||
|
else:
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class GroupAdmin(admin.ModelAdmin):
|
class GroupAdmin(admin.ModelAdmin):
|
||||||
|
list_select_related = True
|
||||||
|
list_display = (
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'member_count',
|
||||||
|
'has_leader',
|
||||||
|
'_attributes'
|
||||||
|
)
|
||||||
|
|
||||||
|
list_filter = (
|
||||||
|
'authgroup__internal',
|
||||||
|
'authgroup__hidden',
|
||||||
|
'authgroup__open',
|
||||||
|
'authgroup__public',
|
||||||
|
IsAutoGroupFilter
|
||||||
|
)
|
||||||
|
|
||||||
filter_horizontal = ('permissions',)
|
filter_horizontal = ('permissions',)
|
||||||
inlines = (AuthGroupInlineAdmin,)
|
inlines = (AuthGroupInlineAdmin,)
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
queryset = super().get_queryset(request)
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
_member_count=Count('user', distinct=True),
|
||||||
|
)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
def description(self, obj):
|
||||||
|
return obj.authgroup.description
|
||||||
|
|
||||||
|
def member_count(self, obj):
|
||||||
|
return obj._member_count
|
||||||
|
|
||||||
|
member_count.admin_order_field = '_member_count'
|
||||||
|
|
||||||
|
def has_leader(self, obj):
|
||||||
|
return obj.authgroup.group_leaders.exists()
|
||||||
|
|
||||||
|
has_leader.boolean = True
|
||||||
|
|
||||||
|
def _attributes(self, obj):
|
||||||
|
attributes = list()
|
||||||
|
if _has_auto_groups and (obj.managedalliancegroup_set.exists()
|
||||||
|
or obj.managedcorpgroup_set.exists()
|
||||||
|
):
|
||||||
|
attributes.append('Auto Group')
|
||||||
|
elif obj.authgroup.internal:
|
||||||
|
attributes.append('Internal')
|
||||||
|
else:
|
||||||
|
if obj.authgroup.hidden:
|
||||||
|
attributes.append('Hidden')
|
||||||
|
if obj.authgroup.open:
|
||||||
|
attributes.append('Open')
|
||||||
|
if obj.authgroup.public:
|
||||||
|
attributes.append('Public')
|
||||||
|
if not attributes:
|
||||||
|
attributes.append('Default')
|
||||||
|
|
||||||
|
return ', '.join(attributes)
|
||||||
|
|
||||||
|
_attributes.short_description = "Attributes"
|
||||||
|
|
||||||
class Group(BaseGroup):
|
class Group(BaseGroup):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user