mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-22 23:42:25 +00:00
Adherent admin
This commit is contained in:
parent
6ec6f96b41
commit
c32dab80f8
@ -0,0 +1,5 @@
|
|||||||
|
# -*- mode: python; coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
default_app_config = 'adherents.apps.AdherentsConfig'
|
35
adherents/admin.py
Normal file
35
adherents/admin.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# -*- mode: python; coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
|
# 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
|
||||||
|
|
||||||
|
from .forms import CustomUserChangeForm
|
||||||
|
from .models import Profile
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileInline(admin.StackedInline):
|
||||||
|
"""Inline user profile in user admin"""
|
||||||
|
model = Profile
|
||||||
|
can_delete = False
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserAdmin(UserAdmin):
|
||||||
|
inlines = (ProfileInline,)
|
||||||
|
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
|
||||||
|
list_select_related = ('profile',)
|
||||||
|
form = CustomUserChangeForm
|
||||||
|
|
||||||
|
def get_inline_instances(self, request, obj=None):
|
||||||
|
"""
|
||||||
|
When creating a new user don't show profile one the first step
|
||||||
|
"""
|
||||||
|
if not obj:
|
||||||
|
return list()
|
||||||
|
return super().get_inline_instances(request, obj)
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.unregister(User)
|
||||||
|
admin.site.register(User, CustomUserAdmin)
|
11
adherents/apps.py
Normal file
11
adherents/apps.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# -*- mode: python; coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class AdherentsConfig(AppConfig):
|
||||||
|
name = 'adherents'
|
||||||
|
verbose_name = _('adherents')
|
17
adherents/forms.py
Normal file
17
adherents/forms.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# -*- mode: python; coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from django.contrib.auth.forms import UserChangeForm
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserChangeForm(UserChangeForm):
|
||||||
|
"""
|
||||||
|
Make first name, last name and email required
|
||||||
|
in the default Django Auth User model
|
||||||
|
"""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['first_name'].required = True
|
||||||
|
self.fields['last_name'].required = True
|
||||||
|
self.fields['email'].required = True
|
@ -1,5 +1,5 @@
|
|||||||
# -*- mode: python; coding: utf-8 -*-
|
# -*- mode: python; coding: utf-8 -*-
|
||||||
# Copyright (C) 2016-2019 by BDE
|
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
Loading…
Reference in New Issue
Block a user