Commit d9a3b179 authored by Florent Chehab's avatar Florent Chehab

feat(custom user model, admin)

* The custom user model previously introduced can now be fully edited in the admin of the site.
parent 6ce40dc9
Pipeline #37944 passed with stages
in 4 minutes and 26 seconds
from rest_framework.authtoken.admin import TokenAdmin
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm
from rest_framework.authtoken.admin import TokenAdmin
from .models import User from .models import User
admin.site.register(User, UserAdmin)
# Handling of the registration of the custom User model to make sure
# we can see all the fields.
# taken from: https://stackoverflow.com/a/15013810
class CustomUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User
class CustomUserAdmin(UserAdmin):
form = CustomUserChangeForm
fieldsets = UserAdmin.fieldsets + (
(
None,
{"fields": ("allow_sharing_personal_info", "secondary_email", "pseudo")},
),
)
admin.site.register(User, CustomUserAdmin)
# Pour la génération de token dans l'administration du site. # Pour la génération de token dans l'administration du site.
TokenAdmin.raw_id_fields = ("user",) TokenAdmin.raw_id_fields = ("user",)
...@@ -18,8 +18,8 @@ def validate(user, allow_sharing_personal_info): ...@@ -18,8 +18,8 @@ def validate(user, allow_sharing_personal_info):
Custom validation to ensure that moderators, DRI and staff can't be "anonymous" on the plateform Custom validation to ensure that moderators, DRI and staff can't be "anonymous" on the plateform
""" """
if ( if (
get_user_level(user) >= OBJ_MODERATION_PERMISSIONS["moderator"] get_user_level(user) >= OBJ_MODERATION_PERMISSIONS["moderator"]
and not allow_sharing_personal_info and not allow_sharing_personal_info
): ):
raise ValidationError( raise ValidationError(
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment