From 6080af961a224914ce0ac15f48fc392c5580d094 Mon Sep 17 00:00:00 2001 From: Lebaud Antoine Date: Wed, 14 Feb 2024 22:22:36 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9(backend)=20fix=20Django=20Admin=20?= =?UTF-8?q?UserAdmin=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *Broken Identity string representation Resolving a format error in the Identity string representation caused by potential None values in the email field. This issue was discovered when attempting to access the User details page in the Django Admin *Broken User creation form The replacement of the User's username with an email led to errors in the UserAdmin class. The base class used the 'username' field in the 'add_fieldsets' attribute. This problem was discovered while attempting to create a new user in the Django Admin. --- src/backend/core/admin.py | 9 +++++++++ src/backend/core/models.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/core/admin.py b/src/backend/core/admin.py index 5ab86bb..8f6ac75 100644 --- a/src/backend/core/admin.py +++ b/src/backend/core/admin.py @@ -82,6 +82,15 @@ class UserAdmin(auth_admin.UserAdmin): ), (_("Important dates"), {"fields": ("created_at", "updated_at")}), ) + add_fieldsets = ( + ( + None, + { + "classes": ("wide",), + "fields": ("email", "password1", "password2"), + }, + ), + ) inlines = (IdentityInline, TeamAccessInline) list_display = ( "email", diff --git a/src/backend/core/models.py b/src/backend/core/models.py index f9f7cde..368edb5 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -288,7 +288,8 @@ class Identity(BaseModel): def __str__(self): main_str = "[main]" if self.is_main else "" - return f"{self.email:s}{main_str:s}" + id_str = self.email or self.sub + return f"{id_str:s}{main_str:s}" def save(self, *args, **kwargs): """Ensure users always have one and only one main identity."""