From e27dae34ba864ba4e0cfd6ef9b016950612dba56 Mon Sep 17 00:00:00 2001 From: Ulrich K Date: Wed, 10 May 2023 09:44:45 +0200 Subject: [PATCH] 2712: lint changes --- bookwyrm/forms/custom_form.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bookwyrm/forms/custom_form.py b/bookwyrm/forms/custom_form.py index 4a678182b..b179284dd 100644 --- a/bookwyrm/forms/custom_form.py +++ b/bookwyrm/forms/custom_form.py @@ -35,7 +35,7 @@ class CustomForm(StyledForm): """Save and check perms""" self.instance.raise_not_editable(request.user) return super().save(*args, **kwargs) - + # def clean(self): # self.cleaned_data = super().clean() @@ -47,27 +47,31 @@ class CustomForm(StyledForm): # print(field.widget.__dir__()) # self.add_to_attributes(field, "class", "is-danger") - # return self.cleaned_data - + # return self.cleaned_data + def add_error(self, field, error): super().add_error(field, error) # TODO this (finding the field) is much too complicated; probably this is not the right location? # it is however more or less what super().add_error does... - if (field is None): + if field is None: if isinstance(error, dict): for field_name, messages in error.items(): if field_name in self.fields: - self.add_to_attributes(self.fields[field_name], "class", "is-danger") + self.add_to_attributes( + self.fields[field_name], "class", "is-danger" + ) elif isinstance(error, ValidationError): - if hasattr(error, 'error_dict'): + if hasattr(error, "error_dict"): error = error.error_dict for field_name, error_list in error.items(): if field_name in self.fields: - self.add_to_attributes(self.fields[field_name], "class", "is-danger") - else: + self.add_to_attributes( + self.fields[field_name], "class", "is-danger" + ) + else: self.add_to_attributes(field, "class", "is-danger") - + # TODO this method looks much too complicated for a simple "field.add_class(class)"? def add_to_attributes(self, field, attr_name, value): current_attributes = field.widget.attrs