From 2dd3110027baee82dd69143e025833a5773f1066 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 1 Dec 2021 18:14:05 +0100 Subject: [PATCH] views: translate boolean attributes in profile (#58939) --- src/authentic2/attribute_kinds.py | 1 + tests/test_profile.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index f0cee519..aca9db45 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -327,6 +327,7 @@ DEFAULT_ATTRIBUTE_KINDS = [ 'serialize': lambda x: str(int(bool(x))), 'deserialize': lambda x: bool(int(x)), 'rest_framework_field_class': serializers.NullBooleanField, + 'html_value': lambda attribute, value: _('True') if value else _('False'), }, { 'label': _('date'), diff --git a/tests/test_profile.py b/tests/test_profile.py index 98762ad0..8e0179ca 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -262,3 +262,20 @@ def test_account_view(app, simple_user, settings): assert [x['href'] for x in response.html.find('div', {'id': 'a2-profile'}).find_all('a')] == [ reverse('profile_edit'), ] + + +def test_account_view_boolean(app, simple_user, settings): + settings.LANGUAGE_CODE = 'fr' + + Attribute.objects.create( + name='accept', label='Accept', kind='boolean', user_visible=True, user_editable=True + ) + simple_user.attributes.accept = True + + utils.login(app, simple_user) + resp = app.get(reverse('account_management')) + assert 'Vrai' in resp.text + + simple_user.attributes.accept = False + resp = app.get(reverse('account_management')) + assert 'Vrai' not in resp.text -- 2.30.2