From 5c6c3264a52dbb58b9f9da375099e04031c2267c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 14 Feb 2019 10:47:25 +0100 Subject: [PATCH 1/6] forms: PEP8ness, style (#30252) --- src/authentic2/forms/__init__.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/authentic2/forms/__init__.py b/src/authentic2/forms/__init__.py index ee887e14..26a4ac1c 100644 --- a/src/authentic2/forms/__init__.py +++ b/src/authentic2/forms/__init__.py @@ -1,3 +1,19 @@ +# +# Copyright (C) 2010-2019 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + import math from django import forms @@ -93,9 +109,8 @@ class BaseUserForm(forms.ModelForm): verified_attributes[av.attribute.name] = True for attribute in self.attributes: - if attribute.name in self.fields and not attribute.name in verified_attributes: - attribute.set_value(self.instance, - self.cleaned_data[attribute.name]) + if attribute.name in self.fields and attribute.name not in verified_attributes: + attribute.set_value(self.instance, self.cleaned_data[attribute.name]) def save(self, commit=True): result = super(BaseUserForm, self).save(commit=commit) @@ -103,6 +118,7 @@ class BaseUserForm(forms.ModelForm): self.save_attributes() else: old = self.save_m2m + def save_m2m(*args, **kwargs): old(*args, **kwargs) self.save_attributes() @@ -113,6 +129,7 @@ class BaseUserForm(forms.ModelForm): class EditProfileForm(NextUrlFormMixin, BaseUserForm): pass + def modelform_factory(model, **kwargs): '''Build a modelform for the given model, @@ -135,7 +152,7 @@ def modelform_factory(model, **kwargs): continue d[attribute.name] = attribute.get_form_field() for field in app_settings.A2_REQUIRED_FIELDS: - if not field in required: + if field not in required: required.append(field) if not form or not hasattr(form, 'Meta'): meta_d = {'model': model, 'fields': '__all__'} @@ -202,7 +219,7 @@ class AuthenticationForm(auth_forms.AuthenticationForm): try: super(AuthenticationForm, self).clean() - except: + except Exception: if keys: self.exponential_backoff.failure(*keys) raise -- 2.20.1