From 3044f18900fca137ba7b152112fc9d3d4b9ad46f Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Sun, 28 May 2023 17:38:51 +0200 Subject: [PATCH 1/2] [ADDED] Ukrainian to `UserProfile.LANGUAGE_CHOICES` --- .../0021_alter_userprofile_language.py | 34 +++++++++++++++++++ allianceauth/authentication/models.py | 1 + 2 files changed, 35 insertions(+) create mode 100644 allianceauth/authentication/migrations/0021_alter_userprofile_language.py diff --git a/allianceauth/authentication/migrations/0021_alter_userprofile_language.py b/allianceauth/authentication/migrations/0021_alter_userprofile_language.py new file mode 100644 index 00000000..be9ab240 --- /dev/null +++ b/allianceauth/authentication/migrations/0021_alter_userprofile_language.py @@ -0,0 +1,34 @@ +# Generated by Django 4.0.10 on 2023-05-28 15:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("authentication", "0020_userprofile_language_userprofile_night_mode"), + ] + + operations = [ + migrations.AlterField( + model_name="userprofile", + name="language", + field=models.CharField( + blank=True, + choices=[ + ("en", "English"), + ("de", "German"), + ("es", "Spanish"), + ("zh-hans", "Chinese Simplified"), + ("ru", "Russian"), + ("ko", "Korean"), + ("fr", "French"), + ("ja", "Japanese"), + ("it", "Italian"), + ("uk", "Ukrainian"), + ], + default="", + max_length=10, + verbose_name="Language", + ), + ), + ] diff --git a/allianceauth/authentication/models.py b/allianceauth/authentication/models.py index 80fdcd4a..92fe5e71 100755 --- a/allianceauth/authentication/models.py +++ b/allianceauth/authentication/models.py @@ -86,6 +86,7 @@ class UserProfile(models.Model): ('fr', _('French')), ('ja', _('Japanese')), ('it', _('Italian')), + ('uk', _('Ukrainian')), ] language = models.CharField( _("Language"), max_length=10, From e8f508cecbd6b58cb2e3b5b8684aa690b63cff4e Mon Sep 17 00:00:00 2001 From: Peter Pfeufer Date: Sun, 28 May 2023 18:31:50 +0200 Subject: [PATCH 2/2] [CHANGE] Switched to more modern `models.TextChoices` class for languages --- allianceauth/authentication/models.py | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/allianceauth/authentication/models.py b/allianceauth/authentication/models.py index 92fe5e71..6d7a06b8 100755 --- a/allianceauth/authentication/models.py +++ b/allianceauth/authentication/models.py @@ -63,6 +63,22 @@ class UserProfile(models.Model): class Meta: default_permissions = ('change',) + class Language(models.TextChoices): + """ + Choices for UserProfile.language + """ + + ENGLISH = 'en', _('English') + GERMAN = 'de', _('German') + SPANISH = 'es', _('Spanish') + CHINESE = 'zh-hans', _('Chinese Simplified') + RUSSIAN = 'ru', _('Russian') + KOREAN = 'ko', _('Korean') + FRENCH = 'fr', _('French') + JAPANESE = 'ja', _('Japanese') + ITALIAN = 'it', _('Italian') + UKRAINIAN = 'uk', _('Ukrainian') + user = models.OneToOneField( User, related_name='profile', @@ -76,21 +92,9 @@ class UserProfile(models.Model): State, on_delete=models.SET_DEFAULT, default=get_guest_state_pk) - LANGUAGE_CHOICES = [ - ('en', _('English')), - ('de', _('German')), - ('es', _('Spanish')), - ('zh-hans', _('Chinese Simplified')), - ('ru', _('Russian')), - ('ko', _('Korean')), - ('fr', _('French')), - ('ja', _('Japanese')), - ('it', _('Italian')), - ('uk', _('Ukrainian')), - ] language = models.CharField( _("Language"), max_length=10, - choices=LANGUAGE_CHOICES, + choices=Language.choices, blank=True, default='') night_mode = models.BooleanField(