*: fix formatting

This commit is contained in:
Jens Langhammer 2020-11-22 22:14:36 +01:00
parent d5e34bb71d
commit fa004876e9
8 changed files with 28 additions and 17 deletions

View File

@ -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

View File

@ -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)

View File

@ -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}"

View File

@ -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}"

View File

@ -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()),
}

View File

@ -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}"

View File

@ -5,6 +5,8 @@ from passbook.stages.password.views import UserSettingsCardView
urlpatterns = [
path(
"<uuid:stage_uuid>/change-card/", UserSettingsCardView.as_view(), name="user-settings"
"<uuid:stage_uuid>/change-card/",
UserSettingsCardView.as_view(),
name="user-settings",
),
]

View File

@ -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)