Projet

Général

Profil

0007-to-fixup-format-birtdate-using-locale-in-text-field.patch

Benjamin Dauvergne, 01 juin 2021 11:07

Télécharger (1,99 ko)

Voir les différences:

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(-)
passerelle/apps/franceconnect/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import datetime
17 18
import uuid
18 19

  
19 20
from django.core.cache import cache
......
180 181
                token['dgfip_ir'] = franceconnect.dgfip_ressource_ir_response
181 182
            try:
182 183
                template = Template(self.text_template)
183
                token['text'] = template.render(
184
                    Context({'fc': franceconnect.fc_user_info, 'dgfip': token.get('dgfip_ir')})
185
                )
184
                text_template_context = {
185
                    'fc': franceconnect.fc_user_info.copy(),
186
                    'dgfip': token.get('dgfip_ir'),
187
                }
188
                if franceconnect.fc_user_info.get('birthdate'):
189
                    birthdate = franceconnect.fc_user_info['birthdate']
190
                    try:
191
                        text_template_context['fc']['birthdate'] = datetime.datetime.strptime(
192
                            birthdate, '%Y-%m-%d'
193
                        ).date()
194
                    except ValueError:
195
                        pass
196
                token['text'] = template.render(Context(text_template_context))
186 197
            except Exception:
187 198
                token['text'] = '<failed to render>'
188 199
            context['data'] = {'id': self.store(token), 'text': token['text']}
189
-