[damned-lies] chore: flake8 fixes on people
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] chore: flake8 fixes on people
- Date: Fri, 7 May 2021 12:21:44 +0000 (UTC)
commit 347c4f2c4d630365b22705dba9f0bd64d05b6a00
Author: Guillaume Bernard <associations guillaume-bernard fr>
Date: Fri Apr 30 11:28:54 2021 +0200
chore: flake8 fixes on people
people/forms.py | 33 ++++++++++++++++++---------------
people/models.py | 20 ++++++++++++--------
people/tests.py | 36 ++++++++++++++++++++----------------
3 files changed, 50 insertions(+), 39 deletions(-)
---
diff --git a/people/forms.py b/people/forms.py
index e79a0416..ce6e475c 100644
--- a/people/forms.py
+++ b/people/forms.py
@@ -8,17 +8,16 @@ from PIL import ImageFile
from django import forms
from django.conf import settings
from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth.forms import UsernameField
+from django.contrib.auth.validators import UnicodeUsernameValidator
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.translation import gettext_lazy, gettext as _
from common.utils import send_mail
-from teams.models import Team
from people.models import Person
-
-from django.contrib.auth.validators import UnicodeUsernameValidator
-from django.contrib.auth.forms import UsernameField
+from teams.models import Team
username_validator = UnicodeUsernameValidator()
@@ -31,11 +30,11 @@ class RegistrationForm(forms.Form):
help_text=gettext_lazy('May contain only letters, numbers, and @/./+/-/_
characters.'),
widget=forms.TextInput(attrs={'class': 'form-control'}))
email = forms.EmailField(widget=forms.TextInput(attrs={'class': 'form-control'}),
- label=gettext_lazy('Email:'))
- password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class':
'form-control'},render_value=False),
+ label=gettext_lazy('Email:'))
+ password1 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'},
render_value=False),
label=gettext_lazy('Password:'), required=False, min_length=7,
help_text=gettext_lazy('At least 7 characters'))
- password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class':
'form-control'},render_value=False),
+ password2 = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'},
render_value=False),
label=gettext_lazy('Confirm password:'), required=False)
def clean_username(self):
@@ -63,9 +62,9 @@ class RegistrationForm(forms.Form):
email = self.cleaned_data['email']
password = self.cleaned_data['password1']
- new_user = Person.objects.create_user(username=username,
- email=email,
- password=password or "!")
+ new_user = Person.objects.create_user(
+ username=username, email=email, password=password
+ )
salt = hashlib.sha1(force_bytes(random.random())).hexdigest()[:5]
activation_key = hashlib.sha1(force_bytes(salt + username)).hexdigest()
new_user.activation_key = activation_key
@@ -74,7 +73,10 @@ class RegistrationForm(forms.Form):
# Send activation email
site_domain = settings.SITE_DOMAIN
activation_url = str(reverse("register_activation", kwargs={'key': activation_key}))
- message = _("This is a confirmation that your registration on %s succeeded. To activate your
account, please click on the link below or copy and paste it in a browser.") % site_domain
+ message = _(
+ "This is a confirmation that your registration on %s succeeded. To activate your account, "
+ "please click on the link below or copy and paste it in a browser."
+ ) % site_domain
message += "\n\nhttps://%s%s\n\n" % (site_domain, activation_url)
message += _("Administrators of %s" % site_domain)
send_mail(_('Account activation'), message, to=[email])
@@ -103,10 +105,11 @@ class DetailForm(forms.ModelForm):
if url:
size = get_image_size(url)
if size[0] > 100 or size[1] > 100:
- raise ValidationError(_(
- "Image too high or too wide (%(width)d×%(height)d, maximum is 100×100 pixels)") % {
- 'width': size[0], 'height': size[1]
- })
+ raise ValidationError(
+ _("Image too high or too wide (%(width)d×%(height)d, maximum is 100×100 pixels)") % {
+ 'width': size[0], 'height': size[1]
+ }
+ )
return url
diff --git a/people/models.py b/people/models.py
index ebdde369..afa5bb37 100644
--- a/people/models.py
+++ b/people/models.py
@@ -11,7 +11,6 @@ from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
-
AVATAR_SERVICES = {
'gravatar.com': 'https://secure.gravatar.com/avatar/{hash}.jpg?{qs}',
# See https://wiki.libravatar.org/api/
@@ -55,7 +54,7 @@ class Person(User):
def clean_unactivated_accounts(cls):
accounts = cls.objects.filter(
activation_key__isnull=False,
- date_joined__lt=(datetime.datetime.now()-datetime.timedelta(days=10))
+ date_joined__lt=(datetime.datetime.now() - datetime.timedelta(days=10))
).exclude(activation_key='')
for account in accounts:
account.delete()
@@ -68,12 +67,17 @@ class Person(User):
- is not module maintainer
- has no reserved module
"""
- accounts = cls.objects.annotate(num_modules=models.Count('maintains_modules')
- ).annotate(num_states=models.Count('state')
- ).filter(last_login__lt=(datetime.datetime.now()-datetime.timedelta(days=730))
- ).exclude(role__role='coordinator'
- ).exclude(num_modules__gt=0
- ).exclude(num_states__gt=0).order_by()
+ accounts = cls.objects.annotate(
+ num_modules=models.Count('maintains_modules')
+ ).annotate(
+ num_states=models.Count('state')
+ ).filter(
+ last_login__lt=(datetime.datetime.now() - datetime.timedelta(days=730))
+ ).exclude(
+ role__role='coordinator'
+ ).exclude(
+ num_modules__gt=0
+ ).exclude(num_states__gt=0).order_by()
for account in accounts:
account.delete()
diff --git a/people/tests.py b/people/tests.py
index a4f9b53b..7ece8daf 100644
--- a/people/tests.py
+++ b/people/tests.py
@@ -11,15 +11,17 @@ from django.utils.safestring import SafeData
from django.utils.translation import gettext as _
from common.utils import pyicu_present
-from people.models import Person, obfuscate_email
from people import forms
+from people.models import Person, obfuscate_email
class PeopleTestCase(TestCase):
def _create_person(self, seq='', **kwargs):
- pn = Person(first_name='John', last_name='Nothing',
- email='jn%s devnull com' % seq, username= 'jn%s' % seq)
+ pn = Person(
+ first_name='John', last_name='Nothing',
+ email='jn%s devnull com' % seq, username='jn%s' % seq
+ )
for key, arg in kwargs.items():
setattr(pn, key, arg)
pn.set_password('password')
@@ -40,9 +42,10 @@ class PeopleTestCase(TestCase):
def test_activate_account(self):
# Testing if is_active is False by default
- response = self.client.post(reverse('register'),
- {'username': 'newuser', 'email': 'newuser example org',
- 'password1': 'blah012', 'password2': 'blah012'})
+ response = self.client.post(
+ reverse('register'),
+ {'username': 'newuser', 'email': 'newuser example org', 'password1': 'blah012', 'password2':
'blah012'}
+ )
self.newu = Person.objects.get(username='newuser')
self.assertFalse(self.newu.is_active)
@@ -52,7 +55,7 @@ class PeopleTestCase(TestCase):
self.assertContains(response, 'Sorry, the key you provided is not valid.')
response = self.client.get('/register/activate/%s' % self.newu.activation_key, follow=True)
- self.assertContains(response, 'Your account has been activated.')
+ self.assertContains(response, 'Your account has been activated.')
self.newu = Person.objects.get(username='newuser')
self.assertTrue(self.newu.is_active)
@@ -82,12 +85,12 @@ class PeopleTestCase(TestCase):
def test_login_by_email(self):
self.pn = self._create_person()
- response = self.client.post(
+ self.client.post(
reverse('login'), data={'username': 'notexist devnull com', 'password': 'password'}
)
user = auth.get_user(self.client)
self.assertFalse(user.is_authenticated)
- response = self.client.post(
+ self.client.post(
reverse('login'), data={'username': 'jn devnull com', 'password': 'password'}
)
user = auth.get_user(self.client)
@@ -105,8 +108,9 @@ class PeopleTestCase(TestCase):
response = self.client.get(reverse('home'))
self.assertContains(
response,
- '<a aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown"
class="dropdown-toggle hidden-xs avatar" href="%s"><img class="img-circle" alt="generic person icon"
src="/static/img/nobody.png"></a>' % (
- reverse('person_detail_username', args=[pn.username]),),
+ '<a aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown"
class="dropdown-toggle'
+ ' hidden-xs avatar" href="%s"><img class="img-circle" alt="generic person icon"'
+ ' src="/static/img/nobody.png"></a>' % (reverse('person_detail_username', args=[pn.username])),
html=True
)
@@ -169,14 +173,14 @@ class PeopleTestCase(TestCase):
lang = Language.objects.create(name='French', locale='fr', team=team)
# Create Users
- p1 = self._create_person(seq='1', last_login=datetime.datetime.now()-datetime.timedelta(days=700))
- p2 = self._create_person(seq='2', last_login=datetime.datetime.now()-datetime.timedelta(days=800))
+ p1 = self._create_person(seq='1', last_login=datetime.datetime.now() - datetime.timedelta(days=700))
+ p2 = self._create_person(seq='2', last_login=datetime.datetime.now() - datetime.timedelta(days=800))
Role.objects.create(team=team, person=p2, role='coordinator')
- p3 = self._create_person(seq='3', last_login=datetime.datetime.now()-datetime.timedelta(days=800))
+ p3 = self._create_person(seq='3', last_login=datetime.datetime.now() - datetime.timedelta(days=800))
module.maintainers.add(p3)
- p4 = self._create_person(seq='4', last_login=datetime.datetime.now()-datetime.timedelta(days=800))
+ p4 = self._create_person(seq='4', last_login=datetime.datetime.now() - datetime.timedelta(days=800))
StateTranslating.objects.create(branch=branch, domain=domain, language=lang, person=p4)
- self._create_person(seq='5', last_login=datetime.datetime.now()-datetime.timedelta(days=800))
+ self._create_person(seq='5', last_login=datetime.datetime.now() - datetime.timedelta(days=800))
# Test only p5 should be deleted
self.assertEqual(Person.objects.all().count(), 5)
Person.clean_obsolete_accounts()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]