From fa004876e95ff71cc241cd55349ec6c2b1b96e0f Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 22 Nov 2020 22:14:36 +0100 Subject: [PATCH] *: fix formatting --- passbook/policies/hibp/forms.py | 1 - passbook/sources/ldap/tasks.py | 7 ++++++- passbook/stages/otp_static/models.py | 6 +++--- passbook/stages/otp_time/models.py | 6 +++--- passbook/stages/password/forms.py | 4 +--- passbook/stages/password/models.py | 6 ++++-- passbook/stages/password/urls.py | 4 +++- passbook/stages/password/views.py | 11 ++++++++--- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/passbook/policies/hibp/forms.py b/passbook/policies/hibp/forms.py index 39bf3254d..2091526ac 100644 --- a/passbook/policies/hibp/forms.py +++ b/passbook/policies/hibp/forms.py @@ -1,7 +1,6 @@ """passbook HaveIBeenPwned Policy forms""" from django import forms -from django.utils.translation import gettext as _ from passbook.policies.forms import GENERAL_FIELDS from passbook.policies.hibp.models import HaveIBeenPwendPolicy diff --git a/passbook/sources/ldap/tasks.py b/passbook/sources/ldap/tasks.py index e92dbb967..952b90a4b 100644 --- a/passbook/sources/ldap/tasks.py +++ b/passbook/sources/ldap/tasks.py @@ -21,7 +21,12 @@ def ldap_sync_all(): @CELERY_APP.task(bind=True, base=MonitoredTask) def ldap_sync(self: MonitoredTask, source_pk: int): """Synchronization of an LDAP Source""" - source: LDAPSource = LDAPSource.objects.get(pk=source_pk) + try: + source: LDAPSource = LDAPSource.objects.get(pk=source_pk) + except LDAPSource.DoesNotExist: + # Because the source couldn't be found, we don't have a UID + # to set the state with + return self.set_uid(slugify(source.name)) try: syncer = LDAPSynchronizer(source) diff --git a/passbook/stages/otp_static/models.py b/passbook/stages/otp_static/models.py index 851cf6ef7..6cd0f2590 100644 --- a/passbook/stages/otp_static/models.py +++ b/passbook/stages/otp_static/models.py @@ -37,9 +37,9 @@ class OTPStaticStage(ConfigurableStage, Stage): @property def ui_user_settings(self) -> Optional[str]: return reverse( - "passbook_stages_otp_static:user-settings", - kwargs={"stage_uuid": self.stage_uuid}, - ) + "passbook_stages_otp_static:user-settings", + kwargs={"stage_uuid": self.stage_uuid}, + ) def __str__(self) -> str: return f"OTP Static Stage {self.name}" diff --git a/passbook/stages/otp_time/models.py b/passbook/stages/otp_time/models.py index 3da445b57..e7603ecad 100644 --- a/passbook/stages/otp_time/models.py +++ b/passbook/stages/otp_time/models.py @@ -44,9 +44,9 @@ class OTPTimeStage(ConfigurableStage, Stage): @property def ui_user_settings(self) -> Optional[str]: return reverse( - "passbook_stages_otp_time:user-settings", - kwargs={"stage_uuid": self.stage_uuid}, - ) + "passbook_stages_otp_time:user-settings", + kwargs={"stage_uuid": self.stage_uuid}, + ) def __str__(self) -> str: return f"OTP Time (TOTP) Stage {self.name}" diff --git a/passbook/stages/password/forms.py b/passbook/stages/password/forms.py index 71048c55a..6f03030af 100644 --- a/passbook/stages/password/forms.py +++ b/passbook/stages/password/forms.py @@ -53,7 +53,5 @@ class PasswordStageForm(forms.ModelForm): fields = ["name", "backends", "configure_flow", "failed_attempts_before_cancel"] widgets = { "name": forms.TextInput(), - "backends": forms.SelectMultiple( - get_authentication_backends() - ), + "backends": forms.SelectMultiple(get_authentication_backends()), } diff --git a/passbook/stages/password/models.py b/passbook/stages/password/models.py index 4a96e64e3..7c07b5a54 100644 --- a/passbook/stages/password/models.py +++ b/passbook/stages/password/models.py @@ -4,10 +4,10 @@ from typing import Optional, Type from django.contrib.postgres.fields import ArrayField from django.db import models from django.forms import ModelForm +from django.shortcuts import reverse from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer -from django.shortcuts import reverse from passbook.flows.models import ConfigurableStage, Stage @@ -51,7 +51,9 @@ class PasswordStage(ConfigurableStage, Stage): def ui_user_settings(self) -> Optional[str]: if not self.configure_flow: return None - return reverse("passbook_stages_password:user-settings", kwargs={"stage_uuid": self.pk}) + return reverse( + "passbook_stages_password:user-settings", kwargs={"stage_uuid": self.pk} + ) def __str__(self): return f"Password Stage {self.name}" diff --git a/passbook/stages/password/urls.py b/passbook/stages/password/urls.py index dd942286a..d8732fd62 100644 --- a/passbook/stages/password/urls.py +++ b/passbook/stages/password/urls.py @@ -5,6 +5,8 @@ from passbook.stages.password.views import UserSettingsCardView urlpatterns = [ path( - "/change-card/", UserSettingsCardView.as_view(), name="user-settings" + "/change-card/", + UserSettingsCardView.as_view(), + name="user-settings", ), ] diff --git a/passbook/stages/password/views.py b/passbook/stages/password/views.py index 2029ff367..4bfe376f9 100644 --- a/passbook/stages/password/views.py +++ b/passbook/stages/password/views.py @@ -1,18 +1,23 @@ +"""password stage user settings card""" from typing import Any -from django.contrib.auth.mixins import LoginRequiredMixin -from django.views.generic import TemplateView +from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import reverse from django.utils.http import urlencode +from django.views.generic import TemplateView from passbook.flows.views import NEXT_ARG_NAME + class UserSettingsCardView(LoginRequiredMixin, TemplateView): + """Card shown on user settings page to allow user to change their password""" template_name = "stages/password/user-settings-card.html" def get_context_data(self, **kwargs: Any) -> dict[str, Any]: - base_url = reverse("passbook_flows:configure", kwargs={"stage_uuid": self.kwargs["stage_uuid"]}) + base_url = reverse( + "passbook_flows:configure", kwargs={"stage_uuid": self.kwargs["stage_uuid"]} + ) args = urlencode({NEXT_ARG_NAME: reverse("passbook_core:user-settings")}) kwargs = super().get_context_data(**kwargs)