From 2ca5e1eedb6aa9391f2c9f1920f7a4c3ed53020b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 30 Jun 2020 16:12:19 +0200 Subject: [PATCH] stages/otp_*: fix linting --- passbook/stages/otp_static/forms.py | 4 ++-- passbook/stages/otp_static/stage.py | 9 +++++++-- passbook/stages/otp_time/stage.py | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/passbook/stages/otp_static/forms.py b/passbook/stages/otp_static/forms.py index 5d94a17ec..1fa45eadc 100644 --- a/passbook/stages/otp_static/forms.py +++ b/passbook/stages/otp_static/forms.py @@ -1,6 +1,6 @@ """OTP Static forms""" from django import forms -from django.utils.translation import gettext_lazy as _ + from passbook.stages.otp_static.models import OTPStaticStage @@ -12,7 +12,7 @@ class SetupForm(forms.Form): def __init__(self, tokens, *args, **kwargs): super().__init__(*args, **kwargs) print(tokens) - self.fields['tokens'].choices = [(x.token, x.token) for x in tokens] + self.fields["tokens"].choices = [(x.token, x.token) for x in tokens] class OTPStaticStageForm(forms.ModelForm): diff --git a/passbook/stages/otp_static/stage.py b/passbook/stages/otp_static/stage.py index bf5299ca9..a37de0dfb 100644 --- a/passbook/stages/otp_static/stage.py +++ b/passbook/stages/otp_static/stage.py @@ -42,7 +42,11 @@ class OTPStaticStageView(FormView, StageView): if SESSION_STATIC_DEVICE not in self.request.session: device = StaticDevice(user=user, confirmed=True) - tokens = [StaticToken(device=device, token=StaticToken.random_token()) for _ in range(0, stage.token_count)] + tokens = [] + for _ in range(0, stage.token_count): + tokens.append( + StaticToken(device=device, token=StaticToken.random_token()) + ) self.request.session[SESSION_STATIC_DEVICE] = device self.request.session[SESSION_STATIC_TOKENS] = tokens return super().get(request, *args, **kwargs) @@ -51,7 +55,8 @@ class OTPStaticStageView(FormView, StageView): """Verify OTP Token""" device: StaticDevice = self.request.session[SESSION_STATIC_DEVICE] device.save() - [x.save() for x in self.request.session[SESSION_STATIC_TOKENS]] + for token in self.request.session[SESSION_STATIC_TOKENS]: + token.save() del self.request.session[SESSION_STATIC_DEVICE] del self.request.session[SESSION_STATIC_TOKENS] return self.executor.stage_ok() diff --git a/passbook/stages/otp_time/stage.py b/passbook/stages/otp_time/stage.py index a5fb245f5..74e517a2a 100644 --- a/passbook/stages/otp_time/stage.py +++ b/passbook/stages/otp_time/stage.py @@ -9,7 +9,6 @@ from lxml.etree import tostring # nosec from qrcode import QRCode from qrcode.image.svg import SvgFillImage from structlog import get_logger -from django_otp.plugins.otp_totp.models import TOTPDevice from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER from passbook.flows.stage import StageView