Projet

Général

Profil

0001-utils-render-authenticator-response-if-necessary.patch

Valentin Deniaud, 24 juin 2019 18:40

Télécharger (1,89 ko)

Voir les différences:

Subject: [PATCH 1/3] utils: render authenticator response if necessary
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Je sais pas pourquoi mais FormView va retourner des TemplateRespone (pas
rendered) mais au moment de la redirection après un succès la réponse
est déjà rendered. Ça me paraît pas terrible comme comportement donc ce
fix n'est pas terrible non plus, je peux aussi le mettre au niveau du
code qui en a besoin mais ça sera peut-être utile à d'autres
Authenticator, du coup je l'ai mis là.
 src/authentic2/utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/authentic2/utils.py
42 42
from django.utils.six.moves.urllib import parse as urlparse
43 43
from django.shortcuts import resolve_url
44 44
from django.template.loader import render_to_string, TemplateDoesNotExist
45
from django.template.response import ContentNotRenderedError
45 46
from django.core.mail import send_mail
46 47
from django.core import signing
47 48
from django.core.urlresolvers import reverse
......
225 226
    status_code = 200
226 227
    # Some authenticator methods return an HttpResponse, others return a string
227 228
    if isinstance(response, HttpResponse):
228
        content = response.content
229
        try:
230
            content = response.content
231
        except ContentNotRenderedError:
232
            response.render()
233
            content = response.content
229 234
        status_code = response.status_code
230 235
    return {
231 236
        'id': authenticator.id,
232
-