Cleaner error code management

This commit is contained in:
Ludovic Stephan 2019-03-25 23:30:55 +01:00
parent 5f963d5451
commit 2c49b25d59

View file

@ -89,15 +89,9 @@ class LoginExtView(DjangoLoginView):
def form_invalid(self, form):
# forms.non_field_errors() returns strings for some reason
non_field_errors = form.errors["__all__"].as_data()
exte_login_error = next(
(e for e in non_field_errors if e.code in ["has_clipper", "no_password"]),
None,
)
if exte_login_error is not None:
return render(
self.request, "login_error.html", {"error_code": exte_login_error.code}
)
for e in non_field_errors:
if e.code in ["has_clipper", "no_password"]:
return render(self.request, "login_error.html", {"error_code": e.code})
return super().form_invalid(form)