Skip to content

Commit 419d539

Browse files
committed
Running the black code formatter on the codebase
1 parent 173ac11 commit 419d539

File tree

125 files changed

+3957
-1403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+3957
-1403
lines changed

core/admin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
def getDerivedAdmin(base_admin, **kwargs):
88
class DerivedAdmin(base_admin):
99
pass
10+
1011
derived = DerivedAdmin
1112
for k, v in kwargs.iteritems():
1213
setattr(derived, k, getattr(base_admin, k, []) + v)
@@ -26,7 +27,7 @@ class UserProfileInline(admin.StackedInline):
2627

2728

2829
class UserAdmin(auth.admin.UserAdmin):
29-
inlines = (UserProfileInline, )
30+
inlines = (UserProfileInline,)
3031

3132

3233
# Register the admins

core/ajax/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from django.http import HttpResponse
32
import json
43

core/apps.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from core.django_mdmail import convert_md_templates
44

5+
56
class CoreConfig(AppConfig):
67
name = 'core'
78
verbose_name = 'Wasa2il Core'

core/authentication.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def authenticate(self, request, username=None, password=None):
2121

2222
class EmailAuthenticationBackend(CustomAuthenticationBackend):
2323
"""Allow users to log in using their e-mail address"""
24+
2425
def custom_get_user(self, email):
2526
try:
2627
return User.objects.get(email=email)
@@ -30,6 +31,7 @@ def custom_get_user(self, email):
3031

3132
class SSNAuthenticationBackend(CustomAuthenticationBackend):
3233
"""Allow users to log in using their SSN"""
34+
3335
def custom_get_user(self, ssn):
3436
# FIXME: This may be Iceland specific; we ignore dashes.
3537
ssn = ssn.replace('-', '').strip()

core/contextprocessors.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def globals(request):
1313
'INSTANCE_VERSION': settings.WASA2IL_VERSION,
1414
'FEATURES': settings.FEATURES,
1515
'GCM_APP_ID': settings.GCM_APP_ID,
16-
'settings': settings
16+
'settings': settings,
1717
}
1818

1919
# Get global variables from GlobalsMiddleWare.
@@ -25,7 +25,9 @@ def globals(request):
2525
def auto_logged_out(request):
2626
if hasattr(request, 'auto_logged_out') and request.auto_logged_out:
2727
return {
28-
'splash_message': _('For security reasons, you have been automatically logged out due to inactivity.')
28+
'splash_message': _(
29+
'For security reasons, you have been automatically logged out due to inactivity.'
30+
)
2931
}
3032

3133
return {}

core/dataviews.py

+71-70
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,91 @@
33
from election.models import Election
44
from issue.models import Issue
55

6+
67
@jsonize
78
def recent_activity(request):
89

910
# Names prefixed with "q_" to distinguish them as queries. We will be
1011
# returning the same data in JSON format, which we will call "issues" and
1112
# "elections".
12-
q_issues = Issue.objects.select_related('polity').recent().order_by('polity__id', '-deadline_votes')
13-
q_elections = Election.objects.prefetch_related(
14-
'electionvote_set',
15-
'candidate_set'
16-
).select_related(
17-
'result'
18-
).recent()
13+
q_issues = (
14+
Issue.objects.select_related('polity')
15+
.recent()
16+
.order_by('polity__id', '-deadline_votes')
17+
)
18+
q_elections = (
19+
Election.objects.prefetch_related('electionvote_set', 'candidate_set')
20+
.select_related('result')
21+
.recent()
22+
)
1923

2024
issues = []
2125
for q_issue in q_issues:
22-
issues.append({
23-
# Web location for further info on the issue.
24-
'url': request.build_absolute_uri(
25-
reverse('issue', args=(q_issue.polity_id, q_issue.id))
26-
),
27-
28-
# The polity to which this issue belongs.
29-
'polity': q_issue.polity.name,
30-
31-
# The polity's short name, if available.
32-
'polity_shortname': q_issue.polity.name_short,
33-
34-
# A unique identifier for formal reference. Example: 6/2019
35-
'log_number': '%d/%d' % (q_issue.issue_num, q_issue.issue_year),
36-
37-
# The issue's name or title.
38-
'name': q_issue.name,
39-
40-
# Options are: concluded/voting/accepting_proposals/discussion
41-
# Note that the state does not give the *result*, i.e. whether the
42-
# proposal was accepted or rejected, but rather where the issue is
43-
# currently in the decision-making process. Therefore "concluded"
44-
# only means that the issue has concluded, but does not tell us
45-
# *how* it concluded.
46-
'state': q_issue.issue_state(),
47-
48-
# Translated, human-readable version of the issue state.
49-
'state_human_readable': q_issue.get_issue_state_display(),
50-
51-
# A boolean indicating whether the issue has been approved or not.
52-
'majority_reached': q_issue.majority_reached(),
53-
54-
# Translated, human-readable version of the result.
55-
'majority_reached_human_readable': q_issue.get_majority_reached_display(),
56-
57-
# When the issue's fate is not determined by vote from within
58-
# Wasa2il, for example when a vote is made outside of Wasa2il but
59-
# still placed here for reference or historical reasons, or when
60-
# an issue is retracted without ever coming to a vote.
61-
#
62-
# Consider displaying only this value if it is non-null, and the
63-
# `majority_reached` value only if this is null.
64-
'special_process': q_issue.special_process,
65-
66-
# Translated, human-readable version of the result.
67-
'special_process_human_readable': q_issue.get_special_process_display(),
68-
69-
# Comment count.
70-
'comment_count': q_issue.comment_count,
71-
72-
# Vote count.
73-
'vote_count': q_issue.votecount,
74-
})
26+
issues.append(
27+
{
28+
# Web location for further info on the issue.
29+
'url': request.build_absolute_uri(
30+
reverse('issue', args=(q_issue.polity_id, q_issue.id))
31+
),
32+
# The polity to which this issue belongs.
33+
'polity': q_issue.polity.name,
34+
# The polity's short name, if available.
35+
'polity_shortname': q_issue.polity.name_short,
36+
# A unique identifier for formal reference. Example: 6/2019
37+
'log_number': '%d/%d'
38+
% (q_issue.issue_num, q_issue.issue_year),
39+
# The issue's name or title.
40+
'name': q_issue.name,
41+
# Options are: concluded/voting/accepting_proposals/discussion
42+
# Note that the state does not give the *result*, i.e. whether the
43+
# proposal was accepted or rejected, but rather where the issue is
44+
# currently in the decision-making process. Therefore "concluded"
45+
# only means that the issue has concluded, but does not tell us
46+
# *how* it concluded.
47+
'state': q_issue.issue_state(),
48+
# Translated, human-readable version of the issue state.
49+
'state_human_readable': q_issue.get_issue_state_display(),
50+
# A boolean indicating whether the issue has been approved or not.
51+
'majority_reached': q_issue.majority_reached(),
52+
# Translated, human-readable version of the result.
53+
'majority_reached_human_readable': q_issue.get_majority_reached_display(),
54+
# When the issue's fate is not determined by vote from within
55+
# Wasa2il, for example when a vote is made outside of Wasa2il but
56+
# still placed here for reference or historical reasons, or when
57+
# an issue is retracted without ever coming to a vote.
58+
#
59+
# Consider displaying only this value if it is non-null, and the
60+
# `majority_reached` value only if this is null.
61+
'special_process': q_issue.special_process,
62+
# Translated, human-readable version of the result.
63+
'special_process_human_readable': q_issue.get_special_process_display(),
64+
# Comment count.
65+
'comment_count': q_issue.comment_count,
66+
# Vote count.
67+
'vote_count': q_issue.votecount,
68+
}
69+
)
7570

7671
elections = []
7772
for q_election in q_elections:
7873
# See comments for issue above, which are more detailed but are mostly
7974
# applicable to this section as well.
80-
elections.append({
81-
'url': request.build_absolute_uri(reverse('election', args=(q_election.polity_id, q_election.id))),
82-
'polity': q_election.polity.name,
83-
'polity_shortname': q_election.polity.name_short,
84-
'name': q_election.name,
85-
'state': q_election.election_state(),
86-
'state_human_readable': q_election.get_election_state_display(),
87-
'candidate_count': q_election.candidate_set.count(),
88-
'vote_count': q_election.get_vote_count(),
89-
})
75+
elections.append(
76+
{
77+
'url': request.build_absolute_uri(
78+
reverse(
79+
'election', args=(q_election.polity_id, q_election.id)
80+
)
81+
),
82+
'polity': q_election.polity.name,
83+
'polity_shortname': q_election.polity.name_short,
84+
'name': q_election.name,
85+
'state': q_election.election_state(),
86+
'state_human_readable': q_election.get_election_state_display(),
87+
'candidate_count': q_election.candidate_set.count(),
88+
'vote_count': q_election.get_vote_count(),
89+
}
90+
)
9091

9192
return {
9293
'elections': elections,

core/django_mdmail.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
from django.conf import settings
4848
from django.core.mail import EmailMultiAlternatives
49+
4950
if sys.version_info[0] == 3:
5051
from email.mime.image import MIMEImage
5152
else:
@@ -57,17 +58,24 @@
5758
OVERRIDE_WARNING = 'WARNING! THIS FILE IS AUTO-GENERATED by django_mdmail upon Django startup. Changes to this file WILL be overwritten. In the same directory, there should be a file with the same name, except an ".md" ending (for Markdown). Edit that instead and restart Django.'
5859

5960

60-
def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None):
61+
def send_mail(
62+
subject,
63+
message,
64+
from_email,
65+
recipient_list,
66+
fail_silently=False,
67+
auth_user=None,
68+
auth_password=None,
69+
connection=None,
70+
html_message=None,
71+
):
6172

6273
# Have `mdmail` do its Markdown magic.
6374
content = EmailContent(message)
6475

6576
# Create the email message and fill it with the relevant data.
6677
email = EmailMultiAlternatives(
67-
subject,
68-
content.text,
69-
from_email,
70-
recipient_list
78+
subject, content.text, from_email, recipient_list
7179
)
7280
email.attach_alternative(html_message or content.html, 'text/html')
7381
email.mixed_subtype = 'related'
@@ -115,7 +123,9 @@ def ready(self):
115123
convert_md_templates()
116124
'''
117125

118-
override_comment = '{%% comment %%}%s{%% endcomment %%}\n' % OVERRIDE_WARNING
126+
override_comment = (
127+
'{%% comment %%}%s{%% endcomment %%}\n' % OVERRIDE_WARNING
128+
)
119129

120130
# Find all the template directories we'll need to process and put them
121131
# in a flat list.

core/forms.py

+31-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ class EmailWantedField(ChoiceWidget):
2121

2222

2323
class UserProfileForm(Wasa2ilForm):
24-
email = EmailField(label=_("E-mail"), help_text=_("You can change your email address, but will then need to verify it."))
24+
email = EmailField(
25+
label=_("E-mail"),
26+
help_text=_(
27+
"You can change your email address, but will then need to verify it."
28+
),
29+
)
2530

2631
class Meta:
2732
model = UserProfile
28-
fields = ('displayname', 'email', 'phone', 'picture', 'bio', 'declaration_of_interests', 'language', 'email_wanted')
33+
fields = (
34+
'displayname',
35+
'email',
36+
'phone',
37+
'picture',
38+
'bio',
39+
'declaration_of_interests',
40+
'language',
41+
'email_wanted',
42+
)
2943

3044
# We need to keep the 'request' object for certain kinds of validation ('picture' in this case)
3145
def __init__(self, *args, **kwargs):
@@ -38,15 +52,20 @@ def clean_picture(self):
3852
picture = self.request.FILES.get('picture')
3953
if picture:
4054
if picture.name.find('.') == -1:
41-
raise ValidationError(_('Filename must contain file extension'))
55+
raise ValidationError(
56+
_('Filename must contain file extension')
57+
)
4258
else:
4359
ext = picture.name.split('.')[-1].lower()
4460
allowed_exts = ['jpg', 'jpeg', 'png', 'gif']
4561
if ext not in allowed_exts:
46-
raise ValidationError(u'%s: %s' % (
47-
_('Only the following file endings are allowed'),
48-
', '.join(allowed_exts)
49-
))
62+
raise ValidationError(
63+
u'%s: %s'
64+
% (
65+
_('Only the following file endings are allowed'),
66+
', '.join(allowed_exts),
67+
)
68+
)
5069

5170
return data
5271

@@ -55,13 +74,16 @@ class Wasa2ilRegistrationForm(RegistrationForm):
5574
username = UsernameField(
5675
widget=TextInput(attrs={'autofocus': True}),
5776
label=_('Username'),
58-
help_text=_('Only letters, numbers and the symbols @/./+/-/_ are allowed.') #_('Aðeins er leyfilegt að nota bókstafi, tölustafi og táknin @/./+/-/_')
77+
help_text=_(
78+
'Only letters, numbers and the symbols @/./+/-/_ are allowed.'
79+
), # _('Aðeins er leyfilegt að nota bókstafi, tölustafi og táknin @/./+/-/_')
5980
)
6081
email_wanted = TypedChoiceField(
6182
choices=((True, _('Yes')), (False, _('No'))),
6283
widget=EmailWantedField,
63-
label=_('Consent for sending email')
84+
label=_('Consent for sending email'),
6485
)
6586

87+
6688
class PushNotificationForm(Form):
6789
text = CharField(label=_('Message'))

core/management/commands/closeissues.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from core.models import *
77

8-
class Command(BaseCommand):
98

9+
class Command(BaseCommand):
1010
def handle(self, *args, **options):
1111

1212
now = datetime.now()
@@ -15,7 +15,9 @@ def handle(self, *args, **options):
1515
for i in issues:
1616
if i.deadline_votes > now:
1717

18-
stdout.write("Setting closing time of issue '%s' to now..." % i.name)
18+
stdout.write(
19+
"Setting closing time of issue '%s' to now..." % i.name
20+
)
1921
stdout.flush()
2022

2123
i.deadline_votes = now
@@ -27,4 +29,3 @@ def handle(self, *args, **options):
2729
i.save()
2830

2931
stdout.write(" done\n")
30-

0 commit comments

Comments
 (0)