diff --git a/blitz_api/factories.py b/blitz_api/factories.py index 15923e78..3f2aedb1 100644 --- a/blitz_api/factories.py +++ b/blitz_api/factories.py @@ -22,6 +22,7 @@ class Meta: first_name = factory.Faker('first_name') last_name = factory.Faker('last_name') + language = User.LANGUAGE_FR username = factory.Sequence(lambda n: f'John{n}') email = factory.Sequence(lambda n: f'john{n}@blitz.com') password = 'Test123!' diff --git a/blitz_api/migrations/0021_auto_20191010_1045.py b/blitz_api/migrations/0021_auto_20191010_1045.py new file mode 100644 index 00000000..a2571070 --- /dev/null +++ b/blitz_api/migrations/0021_auto_20191010_1045.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.6 on 2019-10-10 14:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blitz_api', '0020_auto_20190529_1200'), + ] + + operations = [ + migrations.AddField( + model_name='historicaluser', + name='language', + field=models.CharField(blank=True, choices=[('en', 'English'), ('fr', 'French')], max_length=100, null=True, verbose_name='Language'), + ), + migrations.AddField( + model_name='user', + name='language', + field=models.CharField(blank=True, choices=[('en', 'English'), ('fr', 'French')], max_length=100, null=True, verbose_name='Language'), + ), + ] diff --git a/blitz_api/models.py b/blitz_api/models.py index 5f06f946..e5a8f946 100644 --- a/blitz_api/models.py +++ b/blitz_api/models.py @@ -19,6 +19,8 @@ class User(AbstractUser): """Abstraction of the base User model. Needed to extend in the future.""" + LANGUAGE_FR = 'fr' + LANGUAGE_EN = 'en' GENDER_CHOICES = ( ('M', _("Male")), @@ -26,6 +28,10 @@ class User(AbstractUser): ('T', _("Trans")), ('A', _("Do not wish to identify myself")), ) + LANGUAGE_CHOICES = ( + (LANGUAGE_EN, _('English')), + (LANGUAGE_FR, _('French')), + ) phone = models.CharField( verbose_name=_("Phone number"), @@ -90,6 +96,13 @@ class User(AbstractUser): choices=GENDER_CHOICES, verbose_name=_("Gender"), ) + language = models.CharField( + max_length=100, + choices=LANGUAGE_CHOICES, + verbose_name=_("Language"), + null=True, + blank=True + ) membership = models.ForeignKey( 'store.Membership', blank=True, diff --git a/blitz_api/tests/tests_view_Users.py b/blitz_api/tests/tests_view_Users.py index 77bcc09d..8a3a63d1 100644 --- a/blitz_api/tests/tests_view_Users.py +++ b/blitz_api/tests/tests_view_Users.py @@ -649,6 +649,7 @@ def test_list_users(self): 'academic_level', 'academic_field', 'gender', + 'language', 'birthdate', 'groups', 'user_permissions', @@ -710,6 +711,7 @@ def test_list_users_with_search(self): 'academic_level', 'academic_field', 'gender', + 'language', 'birthdate', 'groups', 'user_permissions', diff --git a/blitz_api/tests/tests_view_UsersId.py b/blitz_api/tests/tests_view_UsersId.py index 58e65c78..716b220a 100644 --- a/blitz_api/tests/tests_view_UsersId.py +++ b/blitz_api/tests/tests_view_UsersId.py @@ -40,6 +40,7 @@ def setUpClass(cls): 'academic_level', 'academic_field', 'gender', + 'language', 'birthdate', 'groups', 'user_permissions', @@ -649,6 +650,7 @@ def test_update_user_with_permission(self): 'academic_field': {'name': "random_field"}, 'academic_level': {'name': "random_level"}, 'gender': "M", + 'language': "en", 'birthdate': "1999-11-11", } @@ -676,6 +678,7 @@ def test_update_user_with_permission(self): # Check if update was successful self.assertEqual(content['phone'], data['phone']) + self.assertEqual(content['language'], data['language']) self.assertTrue(self.user.check_password("!321tset")) # Check id of the user diff --git a/retirement/tests/tests_viewset_Reservation.py b/retirement/tests/tests_viewset_Reservation.py index 836b4ca1..f7599df2 100644 --- a/retirement/tests/tests_viewset_Reservation.py +++ b/retirement/tests/tests_viewset_Reservation.py @@ -301,6 +301,7 @@ def test_create(self): 'academic_level': None, 'birthdate': None, 'gender': None, + 'language': User.LANGUAGE_FR, 'groups': [], 'id': self.user.id, 'is_active': True,