forms: PEP8ness, style (#30252)

This commit is contained in:
Benjamin Dauvergne 2019-02-14 10:47:25 +01:00
parent bc6892289e
commit f29496c5f1
1 changed files with 22 additions and 5 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
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