diff --git a/fiesta/apps/accounts/admin.py b/fiesta/apps/accounts/admin.py index 58feb9b2..01e80b7e 100644 --- a/fiesta/apps/accounts/admin.py +++ b/fiesta/apps/accounts/admin.py @@ -53,11 +53,18 @@ def get_queryset(self, request): @admin.register(UserProfile) class UserProfileAdmin(admin.ModelAdmin): - list_display = ("user", "nationality", "gender", "picture") + list_display = ( + "user_name", + "user", + "nationality", + "gender", + "faculty", + "picture", + ) list_filter = ( "user__memberships__section", "gender", - ("nationality", admin.AllValuesFieldListFilter), + "nationality", ) autocomplete_fields = ("user",) search_fields = [ @@ -66,6 +73,9 @@ class UserProfileAdmin(admin.ModelAdmin): "user__last_name", ] + def user_name(self, obj): + return obj.user.get_full_name() + def get_queryset(self, request): return ( super() diff --git a/fiesta/apps/plugins/models/plugin.py b/fiesta/apps/plugins/models/plugin.py index b19a333c..4c616da9 100644 --- a/fiesta/apps/plugins/models/plugin.py +++ b/fiesta/apps/plugins/models/plugin.py @@ -65,6 +65,8 @@ class Meta: unique_together = (("app_label", "section"),) + ordering = ("section", "app_label") + def clean_fields(self, exclude=None) -> None: if exclude and "configuration" in exclude: return super().clean_fields(exclude=exclude) diff --git a/fiesta/apps/sections/admin.py b/fiesta/apps/sections/admin.py index dbf209ff..c72e83a8 100644 --- a/fiesta/apps/sections/admin.py +++ b/fiesta/apps/sections/admin.py @@ -1,9 +1,13 @@ from __future__ import annotations from django.contrib import admin +from django.db.models import Prefetch +from django.urls import reverse +from django.utils.html import format_html, format_html_join from django.utils.translation import gettext_lazy as _ from ..plugins.admin import BaseChildConfigurationAdmin +from ..plugins.models import Plugin from .models import Section, SectionMembership, SectionsConfiguration, SectionUniversity @@ -21,13 +25,48 @@ class SectionsConfigurationAdmin(BaseChildConfigurationAdmin): @admin.register(Section) class SectionAdmin(admin.ModelAdmin): - list_display = ("name", "country", "space_slug", "all_universities", "memberships_count", "system_state") + list_display = ( + "name", + "country", + "space_slug", + "all_universities", + "all_plugins", + "memberships_count", + "system_state", + ) list_filter = (("country", admin.AllValuesFieldListFilter), "system_state") list_editable = ("system_state",) def get_queryset(self, request): - return super().get_queryset(request).prefetch_related("memberships", "universities") + return ( + super() + .get_queryset(request) + .prefetch_related( + "memberships", + "universities", + Prefetch("plugins", queryset=Plugin.objects.exclude(state=Plugin.State.DISABLED)), + ) + ) + + @admin.display( + description=_("Plugins"), + ) + def all_plugins(self, obj: Section): + return format_html( + "", + format_html_join( + "\n", + "
  • {}
  • ", + ( + ( + reverse("admin:plugins_plugin_change", args=(p.pk,)), + p, + ) + for p in obj.plugins.all() + ), + ), + ) @admin.display( description=_("Memberships"), @@ -39,7 +78,14 @@ def memberships_count(self, obj: Section): description=_("Universities"), ) def all_universities(self, obj: Section): - return ", ".join(map(str, obj.universities.all())) + return format_html( + "", + format_html_join( + "\n", + "
  • {}
  • ", + ((p,) for p in obj.universities.all()), + ), + ) class SectionUniversityInline(admin.StackedInline): model = SectionUniversity