From 838a43f5cd180f15884b684915628f218f944925 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 8 May 2015 15:55:53 +0200 Subject: [PATCH] attribute_kinds: add person title Default presentation is two radio buttons with mister and mrs. --- src/authentic2/app_settings.py | 1 + src/authentic2/attribute_kinds.py | 18 +++++++++++++++++- src/authentic2/locale/fr/LC_MESSAGES/django.po | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/authentic2/app_settings.py b/src/authentic2/app_settings.py index 3a4a6fd..07c0267 100644 --- a/src/authentic2/app_settings.py +++ b/src/authentic2/app_settings.py @@ -155,6 +155,7 @@ default_settings = dict( definition='exponential backoff maximum duration as seconds until ' 'time until next try after a login failure'), A2_VERIFY_SSL=Setting(default=True, definition='Verify SSL certificate in HTTP requests'), + A2_ATTRIBUTE_KIND_TITLE_CHOICES=Setting(default=(), definition='Choices for the title attribute kind'), ) app_settings = AppSettings(default_settings) diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index 801892d..bb0bd3d 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -6,7 +6,7 @@ from itertools import chain from django import forms from django.core.exceptions import ValidationError from django.core.validators import RegexValidator -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils.functional import allow_lazy from django.template.defaultfilters import capfirst @@ -15,6 +15,13 @@ from . import app_settings capfirst = allow_lazy(capfirst, unicode) +DEFAULT_TITLE_CHOICES = ( + pgettext_lazy('title', 'Mrs'), + pgettext_lazy('title', 'Mr'), +) + +def get_title_choices(): + return app_settings.A2_ATTRIBUTE_KIND_TITLE_CHOICES or DEFAULT_TITLE_CHOICES DEFAULT_ATTRIBUTE_KINDS = [ { @@ -22,6 +29,15 @@ DEFAULT_ATTRIBUTE_KINDS = [ 'name': 'string', 'field_class': forms.CharField, }, + { + 'label': _('title'), + 'name': 'title', + 'field_class': forms.ChoiceField, + 'kwargs': { + 'choices': get_title_choices(), + 'widget': forms.RadioSelect, + } + } ] def get_attribute_kinds(): diff --git a/src/authentic2/locale/fr/LC_MESSAGES/django.po b/src/authentic2/locale/fr/LC_MESSAGES/django.po index 7f626f4..f3c3139 100644 --- a/src/authentic2/locale/fr/LC_MESSAGES/django.po +++ b/src/authentic2/locale/fr/LC_MESSAGES/django.po @@ -94,7 +94,21 @@ msgstr "" msgid "Username" msgstr "Identifiant" +#: src/authentic2/attribute_kinds.py:26 +msgid "title" +msgstr "civilité" + +#: src/authentic2/attribute_kinds.py:30 +msgctxt "title" +msgid "Mrs" +msgstr "Madame" + #: src/authentic2/attribute_kinds.py:31 +msgctxt "title" +msgid "Mr" +msgstr "Monsieur" + +#: src/authentic2/attribute_kinds.py:58 msgid "SIRET number must contain 14 digits" msgstr "Le SIRET doit contenir 14 chiffres" -- 2.1.4