views: translate boolean attributes in profile (#58939)

This commit is contained in:
Valentin Deniaud 2021-12-01 18:14:05 +01:00
parent d80c5ef988
commit 026c90d93d
2 changed files with 18 additions and 0 deletions

View File

@ -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'),

View File

@ -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