all: implement black as code formatter

This commit is contained in:
Jens Langhammer
2019-12-31 12:51:16 +01:00
parent 8eb3f0f708
commit 3bd1eadd51
298 changed files with 4825 additions and 3145 deletions

View File

@ -9,21 +9,29 @@ from passbook.core.models import Application, Provider
class ApplicationForm(forms.ModelForm):
"""Application Form"""
provider = forms.ModelChoiceField(queryset=Provider.objects.all().select_subclasses(),
required=False)
provider = forms.ModelChoiceField(
queryset=Provider.objects.all().select_subclasses(), required=False
)
class Meta:
model = Application
fields = ['name', 'slug', 'launch_url', 'icon_url',
'provider', 'policies', 'skip_authorization']
fields = [
"name",
"slug",
"launch_url",
"icon_url",
"provider",
"policies",
"skip_authorization",
]
widgets = {
'name': forms.TextInput(),
'launch_url': forms.TextInput(),
'icon_url': forms.TextInput(),
'policies': FilteredSelectMultiple(_('policies'), False)
"name": forms.TextInput(),
"launch_url": forms.TextInput(),
"icon_url": forms.TextInput(),
"policies": FilteredSelectMultiple(_("policies"), False),
}
labels = {
'launch_url': _('Launch URL'),
'icon_url': _('Icon URL'),
"launch_url": _("Launch URL"),
"icon_url": _("Icon URL"),
}

View File

@ -11,55 +11,64 @@ from passbook.lib.utils.ui import human_list
LOGGER = get_logger()
class LoginForm(forms.Form):
"""Allow users to login"""
title = _('Log in to your account')
title = _("Log in to your account")
uid_field = forms.CharField()
remember_me = forms.BooleanField(required=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if CONFIG.y('passbook.uid_fields') == ['e-mail']:
self.fields['uid_field'] = forms.EmailField()
self.fields['uid_field'].widget.attrs = {
'placeholder': _(human_list([x.title() for x in CONFIG.y('passbook.uid_fields')]))
if CONFIG.y("passbook.uid_fields") == ["e-mail"]:
self.fields["uid_field"] = forms.EmailField()
self.fields["uid_field"].widget.attrs = {
"placeholder": _(
human_list([x.title() for x in CONFIG.y("passbook.uid_fields")])
)
}
def clean_uid_field(self):
"""Validate uid_field after EmailValidator if 'email' is the only selected uid_fields"""
if CONFIG.y('passbook.uid_fields') == ['email']:
validate_email(self.cleaned_data.get('uid_field'))
return self.cleaned_data.get('uid_field')
if CONFIG.y("passbook.uid_fields") == ["email"]:
validate_email(self.cleaned_data.get("uid_field"))
return self.cleaned_data.get("uid_field")
class SignUpForm(forms.Form):
"""SignUp Form"""
title = _('Sign Up')
name = forms.CharField(label=_('Name'),
widget=forms.TextInput(attrs={'placeholder': _('Name')}))
username = forms.CharField(label=_('Username'),
widget=forms.TextInput(attrs={'placeholder': _('Username')}))
email = forms.EmailField(label=_('E-Mail'),
widget=forms.TextInput(attrs={'placeholder': _('E-Mail')}))
password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput(attrs={'placeholder': _('Password')}))
password_repeat = forms.CharField(label=_('Repeat Password'),
widget=forms.PasswordInput(attrs={
'placeholder': _('Repeat Password')
}))
title = _("Sign Up")
name = forms.CharField(
label=_("Name"), widget=forms.TextInput(attrs={"placeholder": _("Name")})
)
username = forms.CharField(
label=_("Username"),
widget=forms.TextInput(attrs={"placeholder": _("Username")}),
)
email = forms.EmailField(
label=_("E-Mail"), widget=forms.TextInput(attrs={"placeholder": _("E-Mail")})
)
password = forms.CharField(
label=_("Password"),
widget=forms.PasswordInput(attrs={"placeholder": _("Password")}),
)
password_repeat = forms.CharField(
label=_("Repeat Password"),
widget=forms.PasswordInput(attrs={"placeholder": _("Repeat Password")}),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# All fields which have initial data supplied are set to read only
if 'initial' in kwargs:
for field in kwargs.get('initial').keys():
self.fields[field].widget.attrs['readonly'] = 'readonly'
if "initial" in kwargs:
for field in kwargs.get("initial").keys():
self.fields[field].widget.attrs["readonly"] = "readonly"
def clean_username(self):
"""Check if username is used already"""
username = self.cleaned_data.get('username')
username = self.cleaned_data.get("username")
if User.objects.filter(username=username).exists():
LOGGER.warning("Username %s already exists", username)
raise ValidationError(_("Username already exists"))
@ -67,7 +76,7 @@ class SignUpForm(forms.Form):
def clean_email(self):
"""Check if email is already used in django or other auth sources"""
email = self.cleaned_data.get('email')
email = self.cleaned_data.get("email")
# Check if user exists already, error early
if User.objects.filter(email=email).exists():
LOGGER.debug("email %s exists in django", email)
@ -76,8 +85,8 @@ class SignUpForm(forms.Form):
def clean_password_repeat(self):
"""Check if Password adheres to filter and if passwords matche"""
password = self.cleaned_data.get('password')
password_repeat = self.cleaned_data.get('password_repeat')
password = self.cleaned_data.get("password")
password_repeat = self.cleaned_data.get("password_repeat")
if password != password_repeat:
raise ValidationError(_("Passwords don't match"))
return self.cleaned_data.get('password_repeat')
return self.cleaned_data.get("password_repeat")

View File

@ -9,24 +9,29 @@ class GroupForm(forms.ModelForm):
"""Group Form"""
members = forms.ModelMultipleChoiceField(
User.objects.all(), required=False, widget=FilteredSelectMultiple('users', False))
User.objects.all(),
required=False,
widget=FilteredSelectMultiple("users", False),
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance.pk:
self.initial['members'] = self.instance.user_set.values_list('pk', flat=True)
self.initial["members"] = self.instance.user_set.values_list(
"pk", flat=True
)
def save(self, *args, **kwargs):
instance = super().save(*args, **kwargs)
if instance.pk:
instance.user_set.clear()
instance.user_set.add(*self.cleaned_data['members'])
instance.user_set.add(*self.cleaned_data["members"])
return instance
class Meta:
model = Group
fields = ['name', 'parent', 'members', 'attributes']
fields = ["name", "parent", "members", "attributes"]
widgets = {
'name': forms.TextInput(),
"name": forms.TextInput(),
}

View File

@ -12,27 +12,27 @@ class InvitationForm(forms.ModelForm):
def clean_fixed_username(self):
"""Check if username is already used"""
username = self.cleaned_data.get('fixed_username')
username = self.cleaned_data.get("fixed_username")
if User.objects.filter(username=username).exists():
raise ValidationError(_('Username is already in use.'))
raise ValidationError(_("Username is already in use."))
return username
def clean_fixed_email(self):
"""Check if email is already used"""
email = self.cleaned_data.get('fixed_email')
email = self.cleaned_data.get("fixed_email")
if User.objects.filter(email=email).exists():
raise ValidationError(_('E-Mail is already in use.'))
raise ValidationError(_("E-Mail is already in use."))
return email
class Meta:
model = Invitation
fields = ['expires', 'fixed_username', 'fixed_email', 'needs_confirmation']
fields = ["expires", "fixed_username", "fixed_email", "needs_confirmation"]
labels = {
'fixed_username': "Force user's username (optional)",
'fixed_email': "Force user's email (optional)",
"fixed_username": "Force user's username (optional)",
"fixed_email": "Force user's email (optional)",
}
widgets = {
'fixed_username': forms.TextInput(),
'fixed_email': forms.TextInput(),
"fixed_username": forms.TextInput(),
"fixed_email": forms.TextInput(),
}

View File

@ -13,10 +13,8 @@ class DebugPolicyForm(forms.ModelForm):
class Meta:
model = DebugPolicy
fields = GENERAL_FIELDS + ['result', 'wait_min', 'wait_max']
fields = GENERAL_FIELDS + ["result", "wait_min", "wait_max"]
widgets = {
'name': forms.TextInput(),
}
labels = {
'result': _('Allow user')
"name": forms.TextInput(),
}
labels = {"result": _("Allow user")}

View File

@ -13,29 +13,30 @@ class UserDetailForm(forms.ModelForm):
class Meta:
model = User
fields = ['username', 'name', 'email']
widgets = {
'name': forms.TextInput
}
fields = ["username", "name", "email"]
widgets = {"name": forms.TextInput}
class PasswordChangeForm(forms.Form):
"""Form to update password"""
password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput(attrs={
'placeholder': _('New Password'),
'autocomplete': 'new-password'
}))
password_repeat = forms.CharField(label=_('Repeat Password'),
widget=forms.PasswordInput(attrs={
'placeholder': _('Repeat Password'),
'autocomplete': 'new-password'
}))
password = forms.CharField(
label=_("Password"),
widget=forms.PasswordInput(
attrs={"placeholder": _("New Password"), "autocomplete": "new-password"}
),
)
password_repeat = forms.CharField(
label=_("Repeat Password"),
widget=forms.PasswordInput(
attrs={"placeholder": _("Repeat Password"), "autocomplete": "new-password"}
),
)
def clean_password_repeat(self):
"""Check if Password adheres to filter and if passwords matche"""
password = self.cleaned_data.get('password')
password_repeat = self.cleaned_data.get('password_repeat')
password = self.cleaned_data.get("password")
password_repeat = self.cleaned_data.get("password_repeat")
if password != password_repeat:
raise ValidationError(_("Passwords don't match"))
return self.cleaned_data.get('password_repeat')
return self.cleaned_data.get("password_repeat")