From a7a88d94c5bfd7dce5e35bd51186f58ec724bfec Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 27 May 2021 12:06:06 +0200 Subject: [PATCH 06/12] =?UTF-8?q?to=20fixup:=20renommage=20fc=5Ftext=5Ftem?= =?UTF-8?q?plate=20->=20text=5Ftemplate=20et=20int=C3=A9gration=20donn?= =?UTF-8?q?=C3=A9es=20dgfip=20au=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../franceconnect/migrations/0001_initial.py | 2 +- passerelle/apps/franceconnect/models.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/passerelle/apps/franceconnect/migrations/0001_initial.py b/passerelle/apps/franceconnect/migrations/0001_initial.py index 79feef72..d8700884 100644 --- a/passerelle/apps/franceconnect/migrations/0001_initial.py +++ b/passerelle/apps/franceconnect/migrations/0001_initial.py @@ -40,7 +40,7 @@ class Migration(migrations.Migration): models.TextField(default='identite_pivot', verbose_name='FranceConnect scopes'), ), ( - 'fc_text_template', + 'text_template', models.TextField( default="{{ given_name }} {{ family_name }} {% if gender == 'male' %}né{% else %}née{% endif %} le {{ birthdate }} à {{ birthplace }}", verbose_name='FranceConnect text template', diff --git a/passerelle/apps/franceconnect/models.py b/passerelle/apps/franceconnect/models.py index 426cdd89..a7d0d957 100644 --- a/passerelle/apps/franceconnect/models.py +++ b/passerelle/apps/franceconnect/models.py @@ -52,12 +52,12 @@ class Resource(BaseResource): fc_scopes = models.TextField(_('FranceConnect scopes'), default='identite_pivot') - fc_text_template = models.TextField( - _('FranceConnect text template'), + text_template = models.TextField( + _('Text template'), default=( - '''{{ given_name }} {{ family_name }} ''' - '''{% if gender == 'male' %}né{% else %}née{% endif %} le {{ birthdate }} ''' - '''à {{ birthplace }}''' + '''{{ fc.given_name }} {{ fc.family_name }} ''' + '''{% if fc.gender == 'male' %}né{% else %}née{% endif %} le {{ fc.birthdate }} ''' + '''à {{ fc.birthplace }}''' ), ) @@ -179,8 +179,10 @@ class Resource(BaseResource): franceconnect.request_dgfip_ir(str(year), id_teleservice=self.dgfip_id_teleservice) token['dgfip_ir'] = franceconnect.dgfip_ressource_ir_response try: - template = Template(self.fc_text_template) - token['text'] = template.render(Context(franceconnect.fc_user_info)) + template = Template(self.text_template) + token['text'] = template.render( + Context({'fc': franceconnect.fc_user_info, 'dgfip': token.get('dgfip_ir')}) + ) except Exception: token['text'] = '' context['data'] = {'id': self.store(token), 'text': token['text']} -- 2.32.0.rc0