Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin: Siden for en afdeling og siden for en forening har nu liste med admins #1057

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion members/admin/department_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,86 @@
from django.db.models.functions import Upper
from django.urls import reverse
from django.utils.safestring import mark_safe
from members.models import Union, Address, Person, Activity
from members.models import (
Union,
Address,
Person,
Activity,
AdminUserInformation,
)
from django.utils.html import escape
from django.http import HttpResponse


class AdminUserDepartmentInline(admin.TabularInline):
model = AdminUserInformation.departments.through

class Media:
css = {"all": ("members/css/custom_admin.css",)} # Include extra css

classes = ["hideheader"]

extra = 0
verbose_name = "Admin Bruger"
verbose_name_plural = "Admin Brugere"

fields = (
"user_username",
"user_first_name",
"user_last_name",
"user_email",
"user_last_login",
)
readonly_fields = (
"user_username",
"user_first_name",
"user_last_name",
"user_email",
"user_last_login",
)

def get_queryset(self, request):
qs = super().get_queryset(request)
# Filter out inactive users and non-staff users
return qs.filter(
adminuserinformation__user__is_active=True,
adminuserinformation__user__is_staff=True,
).select_related("adminuserinformation__user")

def user_username(self, instance):
return instance.adminuserinformation.user.username

user_username.short_description = "Brugernavn"

def user_first_name(self, instance):
return instance.adminuserinformation.user.first_name

user_first_name.short_description = "Fornavn"

def user_last_name(self, instance):
return instance.adminuserinformation.user.last_name

user_last_name.short_description = "Efternavn"

def user_email(self, instance):
return instance.adminuserinformation.user.email

user_email.short_description = "Email"

def user_last_login(self, instance):
return instance.adminuserinformation.user.last_login.strftime(
"%Y-%m-%d %H:%M:%S"
)

user_last_login.short_description = "Sidste login"

def has_add_permission(self, request, obj):
return False

def has_delete_permission(self, request, obj=None):
return False


class UnionDepartmentFilter(admin.SimpleListFilter):
title = "Forening"
parameter_name = "Union"
Expand All @@ -20,6 +95,7 @@ def queryset(self, request, queryset):


class DepartmentAdmin(admin.ModelAdmin):
inlines = [AdminUserDepartmentInline]
list_display = (
"id",
"department_union_link",
Expand Down
76 changes: 71 additions & 5 deletions members/admin/union_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,80 @@
from django.utils.safestring import mark_safe
from django.utils.html import escape

from members.models import (
Address,
Person,
Department,
)
from members.models import Address, Person, Department, AdminUserInformation


class AdminUserUnionInline(admin.TabularInline):
model = AdminUserInformation.unions.through

class Media:
css = {"all": ("members/css/custom_admin.css",)} # Include extra css

classes = ["hideheader"]

extra = 0
verbose_name = "Admin Bruger"
verbose_name_plural = "Admin Brugere"

fields = (
"user_username",
"user_first_name",
"user_last_name",
"user_email",
"user_last_login",
)
readonly_fields = (
"user_username",
"user_first_name",
"user_last_name",
"user_email",
"user_last_login",
)

def get_queryset(self, request):
qs = super().get_queryset(request)
# Filter out inactive users and non-staff users
return qs.filter(
adminuserinformation__user__is_active=True,
adminuserinformation__user__is_staff=True,
).select_related("adminuserinformation__user")

def user_username(self, instance):
return instance.adminuserinformation.user.username

user_username.short_description = "Brugernavn"

def user_first_name(self, instance):
return instance.adminuserinformation.user.first_name

user_first_name.short_description = "Fornavn"

def user_last_name(self, instance):
return instance.adminuserinformation.user.last_name

user_last_name.short_description = "Efternavn"

def user_email(self, instance):
return instance.adminuserinformation.user.email

user_email.short_description = "Email"

def user_last_login(self, instance):
return instance.adminuserinformation.user.last_login.strftime(
"%Y-%m-%d %H:%M:%S"
)

user_last_login.short_description = "Sidste login"

def has_add_permission(self, request, obj):
return False

def has_delete_permission(self, request, obj=None):
return False


class UnionAdmin(admin.ModelAdmin):
inlines = [AdminUserUnionInline]
list_display = (
"id",
"union_link",
Expand Down
Loading