Skip to content

Commit

Permalink
Merge pull request #208 from willkoua/enhancement-TV-250_add_lang_fie…
Browse files Browse the repository at this point in the history
…ld_in_user

add lang field in user model
  • Loading branch information
RignonNoel authored Oct 10, 2019
2 parents 07ad524 + 04d15de commit 95f29b1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions blitz_api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand Down
23 changes: 23 additions & 0 deletions blitz_api/migrations/0021_auto_20191010_1045.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
13 changes: 13 additions & 0 deletions blitz_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@

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")),
('F', _("Female")),
('T', _("Trans")),
('A', _("Do not wish to identify myself")),
)
LANGUAGE_CHOICES = (
(LANGUAGE_EN, _('English')),
(LANGUAGE_FR, _('French')),
)

phone = models.CharField(
verbose_name=_("Phone number"),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions blitz_api/tests/tests_view_Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ def test_list_users(self):
'academic_level',
'academic_field',
'gender',
'language',
'birthdate',
'groups',
'user_permissions',
Expand Down Expand Up @@ -710,6 +711,7 @@ def test_list_users_with_search(self):
'academic_level',
'academic_field',
'gender',
'language',
'birthdate',
'groups',
'user_permissions',
Expand Down
3 changes: 3 additions & 0 deletions blitz_api/tests/tests_view_UsersId.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setUpClass(cls):
'academic_level',
'academic_field',
'gender',
'language',
'birthdate',
'groups',
'user_permissions',
Expand Down Expand Up @@ -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",
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions retirement/tests/tests_viewset_Reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 95f29b1

Please sign in to comment.