From 7f096367918e5944e2327df2740809ab8253f2fc Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 13 Nov 2024 10:14:31 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(backend)=20add=20full=5Fname=20short?= =?UTF-8?q?=5Fname=20on=20User=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following @sampaccoud's work on impress, add new fields to handle user names in our application. @sampaccoud preferred having a full and short names instead of a basic first and last ones, to follow common good practices, and avoid having frontend formating names (from my understanding). Please see commit eee20033 on Impress. --- src/backend/core/factories.py | 2 ++ .../0008_user_full_name_user_short_name.py | 23 +++++++++++++++++++ src/backend/core/models.py | 5 +++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/backend/core/migrations/0008_user_full_name_user_short_name.py diff --git a/src/backend/core/factories.py b/src/backend/core/factories.py index 63f38c8b..74cfcf29 100644 --- a/src/backend/core/factories.py +++ b/src/backend/core/factories.py @@ -23,6 +23,8 @@ class UserFactory(factory.django.DjangoModelFactory): sub = factory.Sequence(lambda n: f"user{n!s}") email = factory.Faker("email") + full_name = factory.Faker("name") + short_name = factory.Faker("first_name") language = factory.fuzzy.FuzzyChoice([lang[0] for lang in settings.LANGUAGES]) password = make_password("password") diff --git a/src/backend/core/migrations/0008_user_full_name_user_short_name.py b/src/backend/core/migrations/0008_user_full_name_user_short_name.py new file mode 100644 index 00000000..90ca6ba8 --- /dev/null +++ b/src/backend/core/migrations/0008_user_full_name_user_short_name.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.1 on 2024-11-13 09:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0007_recording_mode'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='full_name', + field=models.CharField(blank=True, max_length=100, null=True, verbose_name='full name'), + ), + migrations.AddField( + model_name='user', + name='short_name', + field=models.CharField(blank=True, max_length=100, null=True, verbose_name='short name'), + ) + ] diff --git a/src/backend/core/models.py b/src/backend/core/models.py index b9a9de07..381dbd24 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -145,7 +145,10 @@ class User(AbstractBaseUser, BaseModel, auth_models.PermissionsMixin): admin_email = models.EmailField( _("admin email address"), unique=True, blank=True, null=True ) - + full_name = models.CharField(_("full name"), max_length=100, null=True, blank=True) + short_name = models.CharField( + _("short name"), max_length=100, null=True, blank=True + ) language = models.CharField( max_length=10, choices=lazy(lambda: settings.LANGUAGES, tuple)(),