1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 16:02:25 +00:00
nk20/apps/member/admin.py

67 lines
2.1 KiB
Python
Raw Normal View History

2020-02-18 20:30:26 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
2019-07-08 11:59:31 +00:00
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
2020-08-01 13:13:29 +00:00
from django.utils.translation import gettext_lazy as _
from note.templatetags.pretty_money import pretty_money
from note_kfet.admin import admin_site
2020-07-30 13:53:23 +00:00
2019-08-11 14:22:52 +00:00
from .forms import ProfileForm
2020-07-25 17:40:30 +00:00
from .models import Club, Membership, Profile
2019-07-08 11:59:31 +00:00
class ProfileInline(admin.StackedInline):
2019-07-16 07:05:41 +00:00
"""
Inline user profile in user admin
"""
2019-07-08 11:59:31 +00:00
model = Profile
2020-08-05 21:19:17 +00:00
form = ProfileForm
2019-07-08 11:59:31 +00:00
can_delete = False
2020-08-01 13:13:29 +00:00
@admin.register(User, site=admin_site)
2019-07-08 11:59:31 +00:00
class CustomUserAdmin(UserAdmin):
2020-03-07 21:28:59 +00:00
inlines = (ProfileInline,)
2019-07-08 11:59:31 +00:00
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
2020-03-07 21:28:59 +00:00
list_select_related = ('profile',)
2019-07-08 11:59:31 +00:00
def get_inline_instances(self, request, obj=None):
"""
When creating a new user don't show profile one the first step
"""
2020-09-02 20:54:01 +00:00
return super().get_inline_instances(request, obj) if obj else []
2019-07-08 11:59:31 +00:00
2020-08-01 13:13:29 +00:00
@admin.register(Club, site=admin_site)
class ClubAdmin(admin.ModelAdmin):
list_display = ('name', 'parent_club', 'email', 'require_memberships', 'pretty_fee_paid',
'pretty_fee_unpaid', 'membership_start', 'membership_end',)
ordering = ('name',)
search_fields = ('name', 'email',)
def pretty_fee_paid(self, obj):
return pretty_money(obj.membership_fee_paid)
def pretty_fee_unpaid(self, obj):
return pretty_money(obj.membership_fee_unpaid)
pretty_fee_paid.short_description = _("membership fee (paid students)")
pretty_fee_unpaid.short_description = _("membership fee (unpaid students)")
@admin.register(Membership, site=admin_site)
class MembershipAdmin(admin.ModelAdmin):
list_display = ('user', 'club', 'date_start', 'date_end', 'view_roles', 'pretty_fee',)
ordering = ('-date_start', 'club')
def view_roles(self, obj):
return ", ".join(role.name for role in obj.roles.all())
def pretty_fee(self, obj):
return pretty_money(obj.fee)
2019-07-17 07:49:59 +00:00
2020-08-01 13:13:29 +00:00
view_roles.short_description = _("roles")
pretty_fee.short_description = _("fee")