Skip to content

Commit 463b3c1

Browse files
committed
Fixes for pep8 compatibility
1 parent a32f400 commit 463b3c1

File tree

26 files changed

+352
-277
lines changed

26 files changed

+352
-277
lines changed

pgcommitfest/auth.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from Crypto import Random
3636
import time
3737

38+
3839
class AuthBackend(ModelBackend):
3940
# We declare a fake backend that always fails direct authentication -
4041
# since we should never be using direct authentication in the first place!
@@ -48,7 +49,7 @@ def authenticate(self, username=None, password=None):
4849

4950
# Handle login requests by sending them off to the main site
5051
def login(request):
51-
if request.GET.has_key('next'):
52+
if 'next' in request.GET:
5253
# Put together an url-encoded dict of parameters we're getting back,
5354
# including a small nonce at the beginning to make sure it doesn't
5455
# encrypt the same way every time.
@@ -57,33 +58,35 @@ def login(request):
5758
r = Random.new()
5859
iv = r.read(16)
5960
encryptor = AES.new(SHA.new(settings.SECRET_KEY).digest()[:16], AES.MODE_CBC, iv)
60-
cipher = encryptor.encrypt(s + ' ' * (16-(len(s) % 16))) # pad to 16 bytes
61+
cipher = encryptor.encrypt(s + ' ' * (16 - (len(s) % 16))) # pad to 16 bytes
6162

6263
return HttpResponseRedirect("%s?d=%s$%s" % (
63-
settings.PGAUTH_REDIRECT,
64-
base64.b64encode(iv, "-_"),
65-
base64.b64encode(cipher, "-_"),
66-
))
64+
settings.PGAUTH_REDIRECT,
65+
base64.b64encode(iv, "-_"),
66+
base64.b64encode(cipher, "-_"),
67+
))
6768
else:
6869
return HttpResponseRedirect(settings.PGAUTH_REDIRECT)
6970

71+
7072
# Handle logout requests by logging out of this site and then
7173
# redirecting to log out from the main site as well.
7274
def logout(request):
7375
if request.user.is_authenticated():
7476
django_logout(request)
7577
return HttpResponseRedirect("%slogout/" % settings.PGAUTH_REDIRECT)
7678

79+
7780
# Receive an authentication response from the main website and try
7881
# to log the user in.
7982
def auth_receive(request):
80-
if request.GET.has_key('s') and request.GET['s'] == "logout":
83+
if request.GET.get('s', '') == 'logout':
8184
# This was a logout request
8285
return HttpResponseRedirect('/')
8386

84-
if not request.GET.has_key('i'):
87+
if 'i' not in request.GET:
8588
return HttpResponse("Missing IV in url!", status=400)
86-
if not request.GET.has_key('d'):
89+
if 'd' not in request.GET:
8790
return HttpResponse("Missing data in url!", status=400)
8891

8992
# Set up an AES object and decrypt the data we received
@@ -115,7 +118,7 @@ def auth_receive(request):
115118
changed = True
116119
if user.email != data['e'][0]:
117120
user.email = data['e'][0]
118-
changed= True
121+
changed = True
119122
if changed:
120123
user.save()
121124
except User.DoesNotExist:
@@ -153,7 +156,7 @@ def auth_receive(request):
153156

154157
# Finally, check of we have a data package that tells us where to
155158
# redirect the user.
156-
if data.has_key('d'):
159+
if 'd' in data:
157160
(ivs, datas) = data['d'][0].split('$')
158161
decryptor = AES.new(SHA.new(settings.SECRET_KEY).digest()[:16],
159162
AES.MODE_CBC,
@@ -163,7 +166,7 @@ def auth_receive(request):
163166
rdata = urlparse.parse_qs(s, strict_parsing=True)
164167
except ValueError:
165168
return HttpResponse("Invalid encrypted data received.", status=400)
166-
if rdata.has_key('r'):
169+
if 'r' in rdata:
167170
# Redirect address
168171
return HttpResponseRedirect(rdata['r'][0])
169172
# No redirect specified, see if we have it in our settings
@@ -191,7 +194,7 @@ def user_search(searchterm=None, userid=None):
191194
u = urllib.urlopen('%ssearch/?%s' % (
192195
settings.PGAUTH_REDIRECT,
193196
urllib.urlencode(q),
194-
))
197+
))
195198
(ivs, datas) = u.read().split('&')
196199
u.close()
197200

pgcommitfest/commitfest/admin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
from models import *
44

5+
56
class CommitterAdmin(admin.ModelAdmin):
67
list_display = ('user', 'active')
78

9+
810
class PatchOnCommitFestInline(admin.TabularInline):
911
model = PatchOnCommitFest
10-
extra=1
12+
extra = 1
13+
1114

1215
class PatchAdmin(admin.ModelAdmin):
1316
inlines = (PatchOnCommitFestInline,)
1417
list_display = ('name', )
15-
# list_filter = ('commitfests_set__commitfest__name',)
18+
1619

1720
class MailThreadAttachmentAdmin(admin.ModelAdmin):
1821
list_display = ('date', 'author', 'messageid', 'mailthread',)
1922

23+
2024
admin.site.register(Committer, CommitterAdmin)
2125
admin.site.register(CommitFest)
2226
admin.site.register(Topic)

pgcommitfest/commitfest/ajax.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@
1010
import json
1111

1212
from pgcommitfest.auth import user_search
13+
from models import CommitFest, Patch, MailThread, MailThreadAttachment
14+
from models import MailThreadAnnotation, PatchHistory
15+
1316

14-
class HttpResponseServiceUnavailable(HttpResponse):
17+
class HttpResponseServiceUnavailable(HttpResponse):
1518
status_code = 503
1619

20+
1721
class Http503(Exception):
1822
pass
1923

20-
from models import CommitFest, Patch, MailThread, MailThreadAttachment
21-
from models import MailThreadAnnotation, PatchHistory
2224

2325
def _archivesAPI(suburl, params=None):
2426
try:
25-
resp = requests.get("http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
26-
settings.ARCHIVES_SERVER,
27-
settings.ARCHIVES_PORT,
28-
suburl),
29-
params=params,
30-
headers={
31-
'Host': settings.ARCHIVES_HOST,
32-
},
33-
timeout=settings.ARCHIVES_TIMEOUT,
27+
resp = requests.get(
28+
"http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
29+
settings.ARCHIVES_SERVER,
30+
settings.ARCHIVES_PORT,
31+
suburl),
32+
params=params,
33+
headers={
34+
'Host': settings.ARCHIVES_HOST,
35+
},
36+
timeout=settings.ARCHIVES_TIMEOUT,
3437
)
3538
if resp.status_code != 200:
3639
if resp.status_code == 404:
@@ -43,9 +46,10 @@ def _archivesAPI(suburl, params=None):
4346
except Exception as e:
4447
raise Http503("Failed to communicate with archives backend: %s" % e)
4548

49+
4650
def getThreads(request):
47-
search = request.GET.has_key('s') and request.GET['s'] or None
48-
if request.GET.has_key('a') and request.GET['a'] == "1":
51+
search = request.GET.get('s', None)
52+
if request.GET.get('a', '0') == '1':
4953
attachonly = 1
5054
else:
5155
attachonly = 0
@@ -58,6 +62,7 @@ def getThreads(request):
5862
r = _archivesAPI('/list/pgsql-hackers/latest.json', params)
5963
return sorted(r, key=lambda x: x['date'], reverse=True)
6064

65+
6166
def getMessages(request):
6267
threadid = request.GET['t']
6368

@@ -67,6 +72,7 @@ def getMessages(request):
6772
r = _archivesAPI('/message-id.json/%s' % thread.messageid)
6873
return sorted(r, key=lambda x: x['date'], reverse=True)
6974

75+
7076
def refresh_single_thread(thread):
7177
r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
7278
if thread.latestmsgid != r[-1]['msgid']:
@@ -83,6 +89,7 @@ def refresh_single_thread(thread):
8389
p.lastmail = thread.latestmessage
8490
p.save()
8591

92+
8693
@transaction.atomic
8794
def annotateMessage(request):
8895
thread = get_object_or_404(MailThread, pk=int(request.POST['t']))
@@ -112,6 +119,7 @@ def annotateMessage(request):
112119
return 'OK'
113120
return 'Message not found in thread!'
114121

122+
115123
@transaction.atomic
116124
def deleteAnnotation(request):
117125
annotation = get_object_or_404(MailThreadAnnotation, pk=request.POST['id'])
@@ -125,6 +133,7 @@ def deleteAnnotation(request):
125133

126134
return 'OK'
127135

136+
128137
def parse_and_add_attachments(threadinfo, mailthread):
129138
for t in threadinfo:
130139
if len(t['atts']):
@@ -142,6 +151,7 @@ def parse_and_add_attachments(threadinfo, mailthread):
142151
# In theory we should remove objects if they don't have an
143152
# attachment, but how could that ever happen? Ignore for now.
144153

154+
145155
@transaction.atomic
146156
def attachThread(request):
147157
cf = get_object_or_404(CommitFest, pk=int(request.POST['cf']))
@@ -150,6 +160,7 @@ def attachThread(request):
150160

151161
return doAttachThread(cf, patch, msgid, request.user)
152162

163+
153164
def doAttachThread(cf, patch, msgid, user):
154165
# Note! Must be called in an open transaction!
155166
r = sorted(_archivesAPI('/message-id.json/%s' % msgid), key=lambda x: x['date'])
@@ -166,10 +177,10 @@ def doAttachThread(cf, patch, msgid, user):
166177
# While at it, we update the thread entry with the latest data from the
167178
# archives.
168179
thread.patches.add(patch)
169-
thread.latestmessage=r[-1]['date']
170-
thread.latestauthor=r[-1]['from']
171-
thread.latestsubject=r[-1]['subj']
172-
thread.latestmsgid=r[-1]['msgid']
180+
thread.latestmessage = r[-1]['date']
181+
thread.latestauthor = r[-1]['from']
182+
thread.latestsubject = r[-1]['subj']
183+
thread.latestmsgid = r[-1]['msgid']
173184
thread.save()
174185
else:
175186
# No existing thread existed, so create it
@@ -195,6 +206,7 @@ def doAttachThread(cf, patch, msgid, user):
195206

196207
return 'OK'
197208

209+
198210
@transaction.atomic
199211
def detachThread(request):
200212
cf = get_object_or_404(CommitFest, pk=int(request.POST['cf']))
@@ -209,16 +221,18 @@ def detachThread(request):
209221

210222
return 'OK'
211223

224+
212225
def searchUsers(request):
213-
if request.GET.has_key('s') and request.GET['s']:
226+
if request.GET.get('s', ''):
214227
return user_search(request.GET['s'])
215228
else:
216229
return []
217230

231+
218232
def importUser(request):
219-
if request.GET.has_key('u') and request.GET['u']:
233+
if request.GET.get('u', ''):
220234
u = user_search(userid=request.GET['u'])
221-
if len (u) != 1:
235+
if len(u) != 1:
222236
return "Internal error, duplicate user found"
223237

224238
u = u[0]
@@ -235,7 +249,8 @@ def importUser(request):
235249
else:
236250
raise Http404()
237251

238-
_ajax_map={
252+
253+
_ajax_map = {
239254
'getThreads': getThreads,
240255
'getMessages': getMessages,
241256
'attachThread': attachThread,
@@ -246,11 +261,12 @@ def importUser(request):
246261
'importUser': importUser,
247262
}
248263

264+
249265
# Main entrypoint for /ajax/<command>/
250266
@csrf_exempt
251267
@login_required
252268
def main(request, command):
253-
if not _ajax_map.has_key(command):
269+
if command not in _ajax_map:
254270
raise Http404
255271
try:
256272
resp = HttpResponse(content_type='application/json')

pgcommitfest/commitfest/feeds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.syndication.views import Feed
22

3+
34
class ActivityFeed(Feed):
45
title = description = 'Commitfest Activity Log'
56
link = 'https://commitfest.postgresql.org/'
@@ -30,7 +31,7 @@ def item_description(self, item):
3031

3132
def item_link(self, item):
3233
if self.cfid:
33-
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(cfid=self.cfid,**item)
34+
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(cfid=self.cfid, **item)
3435
else:
3536
return 'https://commitfest.postgresql.org/{cfid}/{patchid}/'.format(**item)
3637

pgcommitfest/commitfest/forms.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from widgets import ThreadPickWidget
1313
from ajax import _archivesAPI
1414

15+
1516
class CommitFestFilterForm(forms.Form):
1617
text = forms.CharField(max_length=50, required=False)
1718
status = forms.ChoiceField(required=False)
@@ -28,13 +29,14 @@ def __init__(self, cf, *args, **kwargs):
2829
self.fields['status'] = forms.ChoiceField(choices=c, required=False)
2930

3031
q = Q(patch_author__commitfests=cf) | Q(patch_reviewer__commitfests=cf)
31-
userchoices = [(-1, '* All'), (-2, '* None'), (-3, '* Yourself') ] + [(u.id, '%s %s (%s)' % (u.first_name, u.last_name, u.username)) for u in User.objects.filter(q).distinct().order_by('first_name', 'last_name')]
32+
userchoices = [(-1, '* All'), (-2, '* None'), (-3, '* Yourself')] + [(u.id, '%s %s (%s)' % (u.first_name, u.last_name, u.username)) for u in User.objects.filter(q).distinct().order_by('first_name', 'last_name')]
3233
self.fields['author'] = forms.ChoiceField(choices=userchoices, required=False)
3334
self.fields['reviewer'] = forms.ChoiceField(choices=userchoices, required=False)
3435

3536
for f in ('status', 'author', 'reviewer',):
3637
self.fields[f].widget.attrs = {'class': 'input-medium'}
3738

39+
3840
class PatchForm(forms.ModelForm):
3941
class Meta:
4042
model = Patch
@@ -68,21 +70,24 @@ def clean_threadmsgid(self):
6870
raise ValidationError("Error in API call to validate thread")
6971
return self.cleaned_data['threadmsgid']
7072

73+
7174
def _fetch_thread_choices(patch):
7275
for mt in patch.mailthread_set.order_by('-latestmessage'):
7376
ti = sorted(_archivesAPI('/message-id.json/%s' % mt.messageid), key=lambda x: x['date'], reverse=True)
7477
yield [mt.subject,
75-
[('%s,%s' % (mt.messageid, t['msgid']),'From %s at %s' % (t['from'], t['date'])) for t in ti]]
78+
[('%s,%s' % (mt.messageid, t['msgid']), 'From %s at %s' % (t['from'], t['date'])) for t in ti]]
7679

7780

7881
review_state_choices = (
7982
(0, 'Tested'),
8083
(1, 'Passed'),
8184
)
8285

86+
8387
def reviewfield(label):
8488
return forms.MultipleChoiceField(choices=review_state_choices, label=label, widget=forms.CheckboxSelectMultiple, required=False)
8589

90+
8691
class CommentForm(forms.Form):
8792
responseto = forms.ChoiceField(choices=[], required=True, label='In response to')
8893

@@ -120,12 +125,13 @@ def clean_responseto(self):
120125

121126
def clean(self):
122127
if self.is_review:
123-
for fn,f in self.fields.items():
124-
if fn.startswith('review_') and self.cleaned_data.has_key(fn):
125-
if '1' in self.cleaned_data[fn] and not '0' in self.cleaned_data[fn]:
128+
for fn, f in self.fields.items():
129+
if fn.startswith('review_') and fn in self.cleaned_data:
130+
if '1' in self.cleaned_data[fn] and '0' not in self.cleaned_data[fn]:
126131
self.errors[fn] = (('Cannot pass a test without performing it!'),)
127132
return self.cleaned_data
128133

134+
129135
class BulkEmailForm(forms.Form):
130136
reviewers = forms.CharField(required=False, widget=HiddenInput())
131137
authors = forms.CharField(required=False, widget=HiddenInput())

pgcommitfest/commitfest/lookups.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ def get_item_label(self, item):
2222
# Display for choice listings
2323
return u"%s (%s)" % (item.username, item.get_full_name())
2424

25+
2526
registry.register(UserLookup)

0 commit comments

Comments
 (0)