From dd60de48948c68902272c2ebd3218238c5e51d26 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 27 May 2021 12:20:23 +0200 Subject: [PATCH 07/12] to fixup: format birtdate using locale in text field --- passerelle/apps/franceconnect/models.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/passerelle/apps/franceconnect/models.py b/passerelle/apps/franceconnect/models.py index a7d0d957..a70e756a 100644 --- a/passerelle/apps/franceconnect/models.py +++ b/passerelle/apps/franceconnect/models.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import datetime import uuid from django.core.cache import cache @@ -180,9 +181,19 @@ class Resource(BaseResource): token['dgfip_ir'] = franceconnect.dgfip_ressource_ir_response try: template = Template(self.text_template) - token['text'] = template.render( - Context({'fc': franceconnect.fc_user_info, 'dgfip': token.get('dgfip_ir')}) - ) + text_template_context = { + 'fc': franceconnect.fc_user_info.copy(), + 'dgfip': token.get('dgfip_ir'), + } + if franceconnect.fc_user_info.get('birthdate'): + birthdate = franceconnect.fc_user_info['birthdate'] + try: + text_template_context['fc']['birthdate'] = datetime.datetime.strptime( + birthdate, '%Y-%m-%d' + ).date() + except ValueError: + pass + token['text'] = template.render(Context(text_template_context)) except Exception: token['text'] = '' context['data'] = {'id': self.store(token), 'text': token['text']} -- 2.32.0.rc0