Skip to content

Commit

Permalink
SIO-2051 Fixed pep8 static_check errors after checkers update
Browse files Browse the repository at this point in the history
Change-Id: I55c3581f241f12637e5e38804c9a9020d8478e4d
  • Loading branch information
Norbi-S committed Dec 13, 2017
1 parent 21022f5 commit 7365d97
Show file tree
Hide file tree
Showing 61 changed files with 244 additions and 153 deletions.
9 changes: 7 additions & 2 deletions .pep8rc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
# E126 - continuation line over-indented for hanging indent
# E127 - continuation line over-indented for visual indent
# E128 - continuation line under-indented for visual indent
# E131 - continuation line unaligned for hanging indent
# E133 - closing bracket is missing indentation
# E226 - missing whitespace around arithmetic operator
# E501 - line too long (checked by pylint)
ignore=E121,E122,E123,E126,E127,E128,E133,E226,E501
exclude=migrations
# E731 - do not assign a lambda expression, use a def

# W503 - line break before binary operator

ignore=E121,E122,E123,E126,E127,E128,E131,E133,E226,E501,E731,W503
exclude=migrations,oioioi/default_settings.py
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ignore=migrations
# R0915 = Too many statements
# R0921 = Abstract class not referenced
# R0922 = Abstract class is only referenced %s times
# R1705 - unnecessary "else" after "return"

# C0103 = Invalid name
# C0111 = Missing docstring
Expand All @@ -48,7 +49,7 @@ ignore=migrations

# similarities = similar code fragments

disable=F0401, E1002,E1101,E1120,E1121,E1123, W0142,W0212,W0232,W0613,W0622,W0614, R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0915,R0921,R0922, C0103,C0111,C0302,C0330, I0011,I0013, similarities
disable=F0401, E1002,E1101,E1120,E1121,E1123, W0142,W0212,W0232,W0613,W0622,W0614, R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0915,R0921,R0922,R1705,C0103,C0111,C0302,C0330, I0011,I0013, similarities

[REPORTS]

Expand Down
1 change: 1 addition & 0 deletions oioioi/analytics/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from oioioi.base.tests import TestCase


class TestAnalytics(TestCase):
def test_without_analytics(self):
response = self.client.get('/', follow=True)
Expand Down
6 changes: 4 additions & 2 deletions oioioi/balloons/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def _create_balloon_delivery(self, submission):
accepted_or_unjudged = \
Q(status='OK') | Q(status='?') | Q(status='SE')
not_ignored = Q(kind='NORMAL')
user_is_participant = Q(user__participant__contest=
submission.problem_instance.contest_id)
user_is_participant = Q(
user__participant__contest=submission
.problem_instance.contest_id
)
submissions = Submission.objects \
.filter(accepted_or_unjudged & this_problem_instance
& not_ignored & user_is_participant) \
Expand Down
1 change: 1 addition & 0 deletions oioioi/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def format_callback(obj):

return to_delete, perms_needed, protected


class AdminSite(DjangoAdminSite):
def __init__(self, *args, **kwargs):
super(AdminSite, self).__init__(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion oioioi/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from oioioi.base.utils.user import USERNAME_REGEX
from oioioi.base.preferences import PreferencesSaved


def adjust_username_field(form):
help_text = \
_("This value may contain only letters, numbers and underscore.")
Expand Down Expand Up @@ -67,7 +68,6 @@ def save(self, *args, **kwargs):
return instance



class OioioiUserCreationForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super(OioioiUserCreationForm, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -101,6 +101,7 @@ def clean_email(self):
raise forms.ValidationError(self.error_messages['unknown'])
return email


# http://stackoverflow.com/questions/3657709/how-to-force-save-an-empty-unchanged-django-admin-inline
class AlwaysChangedModelForm(forms.ModelForm):
def has_changed(self):
Expand Down
1 change: 0 additions & 1 deletion oioioi/base/management/commands/system_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def handle(self, *args, **options):
'submission_report__submission',
'submission_report__submission__problem_instance')


frs_out, trs_out = [], []

for fr in frs:
Expand Down
1 change: 1 addition & 0 deletions oioioi/base/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
logger = logging.getLogger(__name__)
thread_data = threading.local()


class NotificationHandler(logging.StreamHandler):
"""This handler catches all logs and emits a notification
if a notification type is set in the extra dictionary,
Expand Down
14 changes: 8 additions & 6 deletions oioioi/base/registration_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ def register(self, form):
]

if not settings.SEND_USER_ACTIVATION_EMAIL:
urlpatterns += [
url(r'^register/complete/$',
TemplateView.as_view(template_name=
'registration/registration_and_activation_complete.html'),
name='registration_complete'),
]
urlpatterns += [url(
r'^register/complete/$',
TemplateView.as_view(
template_name='registration/'
'registration_and_activation_complete.html'
),
name='registration_complete'
)]

urlpatterns += [
url(r'^password/reset/$',
Expand Down
4 changes: 2 additions & 2 deletions oioioi/base/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ def notification_function(arguments):
NotificationHandler.register_notification('test_notification',
notification_function)
logger = logging.getLogger('oioioi')
logger.info("Test notification", extra=
{'notification': 'test_notification'})
logger.info("Test notification",
extra={'notification': 'test_notification'})
self.assertTrue(flags['got_notification'])


Expand Down
1 change: 1 addition & 0 deletions oioioi/base/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.template.loader import render_to_string
from django import forms


# passing classes through the usual attrs attribute won't work
# since the template already specifies it
class DateTimePicker(forms.widgets.DateTimeInput):
Expand Down
5 changes: 3 additions & 2 deletions oioioi/complaints/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from oioioi.participants.models import Participant


@override_settings(EMAIL_BACKEND=
'django.core.mail.backends.locmem.EmailBackend')
@override_settings(
EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend'
)
class TestMakingComplaint(TestCase):
fixtures = ['test_users', 'test_contest']

Expand Down
2 changes: 1 addition & 1 deletion oioioi/confirmations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def verify_submission_receipt_proof(proof, source):
try:
proof_data = unsign_submission_metadata(proof)
except signing.BadSignature as e:
raise ProofCorrupted, str(e), sys.exc_info()[2]
raise ProofCorrupted(str(e), sys.exc_info()[2])

proof_data['date'] = dateutil.parser.parse(proof_data['date'])
source_hash = hashlib.sha256(source).hexdigest()
Expand Down
5 changes: 3 additions & 2 deletions oioioi/contests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ def get_queryset(self, request):

# Because nulls are treated as highest by default,
# this is a workaround to make them smaller than other values.
queryset = queryset.annotate(score_with_nulls_smallest=
Coalesce('score', Value('')))
queryset = queryset.annotate(
score_with_nulls_smallest=Coalesce('score', Value(''))
)
return queryset

def lookup_allowed(self, key, value):
Expand Down
4 changes: 2 additions & 2 deletions oioioi/contests/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
WAIT_FOR_SUBMISSION_SLEEP_SECONDS = 1


#TODO: Improve after migration to Python 3:
# def _get_submission_or_skip(*args, submission_class=Submission)
# TODO: Improve after migration to Python 3:
# def _get_submission_or_skip(*args, submission_class=Submission)
def _get_submission_or_skip(*args, **kwargs):
submission_class = kwargs.get('submission_class', Submission)

Expand Down
2 changes: 1 addition & 1 deletion oioioi/contests/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def process_request(self, request):
# a noncontest version. It could still be a neutral URL.
nonglobal = True
res.namespaces = res.namespaces[1:]
assert not 'contest_id' in res.kwargs
assert 'contest_id' not in res.kwargs
res.kwargs['contest_id'] = contest.id
# If there is a contest-prefixed version of this url,
# reverse will return it.
Expand Down
1 change: 1 addition & 0 deletions oioioi/contests/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from oioioi.contests.controllers import ContestController, \
RegistrationController, PastRoundsHiddenContestControllerMixin


class PrivateRegistrationController(RegistrationController):
@classmethod
def anonymous_can_enter_contest(cls):
Expand Down
14 changes: 8 additions & 6 deletions oioioi/contests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def render_contest_id_view(request):
print RequestContext(request)
return HttpResponse(t.render(RequestContext(request)))


class TestSubmissionListOrder(TestCase):
fixtures = ['test_users', 'test_contest', 'test_full_package',
'test_problem_instance', 'test_submission',
Expand Down Expand Up @@ -165,8 +166,11 @@ def check_order_in_response(self, response, is_descending, error_msg):
test_OK_index = table_content.index(test_OK)
test_CE_index = table_content.index(test_CE)

self.assertEquals(is_descending, test_OK_index < test_CE_index,
error_msg)
self.assertEquals(
is_descending,
test_OK_index < test_CE_index,
error_msg
)


@override_settings(CONTEST_MODE=ContestMode.neutral)
Expand Down Expand Up @@ -919,7 +923,6 @@ def test_view(self):
class TestContestAdmin(TestCase):
fixtures = ['test_users']


def test_simple_contest_create_and_change(self):
self.client.login(username='test_admin')
url = reverse('oioioiadmin:contests_contest_add')
Expand Down Expand Up @@ -1020,7 +1023,7 @@ def test_simple_contest_create_and_change(self):
self.assertIn("Start date should be before end date.",
response.content)
'''
#pylint: enable=pointless-string-statement
# pylint: enable=pointless-string-statement

def test_admin_permissions(self):
url = reverse('oioioiadmin:contests_contest_changelist')
Expand Down Expand Up @@ -1624,7 +1627,6 @@ def fake_request(timestamp):
datetime(2012, 8, 2, 12, 30, 0, tzinfo=utc))))



class TestContestLinks(TestCase):
fixtures = ['test_users', 'test_contest']

Expand Down Expand Up @@ -1846,7 +1848,7 @@ def test_modify_contest(self):
})
response = self.client.post(url, post_data, follow=True)
self.assertEqual(response.status_code, 200)
#self.assertIn('was added successfully', response.content)
# self.assertIn('was added successfully', response.content)
contest = Contest.objects.get()
self.assertEqual(controller_name, contest.controller_name)
ContestPermission(user=User.objects.get(pk=1001), contest=contest,
Expand Down
1 change: 1 addition & 0 deletions oioioi/contests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def contests_by_registration_controller():
rcontrollers[rc.__class__].add(contest.id)
return rcontrollers


@request_cached
def visible_contests(request):
visible = set()
Expand Down
2 changes: 1 addition & 1 deletion oioioi/contests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def user_info_view(request, user_id):
rcontroller = controller.registration_controller()
user = get_object_or_404(User, id=user_id)

if not request.user.is_superuser and (not user in rcontroller
if not request.user.is_superuser and (user not in rcontroller
.filter_users_with_accessible_personal_data(User.objects.all())
or user.is_superuser):
raise PermissionDenied
Expand Down
32 changes: 21 additions & 11 deletions oioioi/evalmgr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ class UserListFilter(SimpleListFilter):
parameter_name = 'user'

def lookups(self, request, model_admin):
users = list(set(QueuedJob.objects
.filter(submission__problem_instance__contest=
request.contest)
.values_list('submission__user__id',
'submission__user__username')))
users = list(
set(
QueuedJob.objects.filter(
submission__problem_instance__contest=request.contest
).values_list(
'submission__user__id',
'submission__user__username'
)
)
)

if (None, None) in users:
users = [x for x in users if x != (None, None)]
users.append(('None', _("(None)")))
Expand All @@ -47,12 +53,16 @@ class ProblemNameListFilter(SimpleListFilter):

def lookups(self, request, model_admin):
# Unique problem names
p_names = list(set(QueuedJob.objects
.filter(submission__problem_instance__contest=
request.contest)
.values_list(
'submission__problem_instance__problem__name',
flat=True)))
p_names = list(
set(
QueuedJob.objects.filter(
submission__problem_instance__contest=request.contest
).values_list(
'submission__problem_instance__problem__name',
flat=True
)
)
)
return [(x, x) for x in p_names]

def queryset(self, request, queryset):
Expand Down
7 changes: 4 additions & 3 deletions oioioi/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class Forum(models.Model):
"""Forum is connected with contest"""

contest = models.OneToOneField(Contest)
visible = models.BooleanField(default=True,
verbose_name=
_("forum is visible after lock"))
visible = models.BooleanField(
default=True,
verbose_name=_("forum is visible after lock")
)
lock_date = models.DateTimeField(blank=True, null=True,
verbose_name=_("autolock date"))
unlock_date = models.DateTimeField(blank=True, null=True,
Expand Down
16 changes: 12 additions & 4 deletions oioioi/mailsubmit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,19 @@ def test_mailsubmit_permissions(self):
self.assertEqual(MailSubmission.objects.count(), 1)

def test_mailsubmissions_list(self):
c1 = Contest(id='contest1', name='Contest1', controller_name=
'oioioi.participants.tests.ParticipantsContestController')
c1 = Contest(
id='contest1',
name='Contest1',
controller_name='oioioi.participants.'
'tests.ParticipantsContestController'
)
c1.save()
c2 = Contest(id='contest2', name='Contest2', controller_name=
'oioioi.participants.tests.ParticipantsContestController')
c2 = Contest(
id='contest2',
name='Contest2',
controller_name='oioioi.participants.'
'tests.ParticipantsContestController'
)
c2.save()
p = Problem.objects.get()
pi1 = ProblemInstance(contest=c1, problem=p,
Expand Down
12 changes: 7 additions & 5 deletions oioioi/notifications/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def notification_processor(request):
def generator():
notifications_session_id = get_notifications_session(
request.session).uid
return render_to_string('notifications/notifications.html',
dict(notif_server_url=
settings.NOTIFICATIONS_SERVER_URL,
notifications_session_id=
notifications_session_id))
return render_to_string(
'notifications/notifications.html',
dict(
notif_server_url=settings.NOTIFICATIONS_SERVER_URL,
notifications_session_id=notifications_session_id
)
)
return {'extra_navbar_right_notifications': lazy(generator, unicode)()}
5 changes: 3 additions & 2 deletions oioioi/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
@jsonify
def notifications_authenticate_view(request):
try:
session = Session.objects.get(notificationssession__uid=
request.POST['nsid'])
session = Session.objects.get(
notificationssession__uid=request.POST['nsid']
)
user_id = session.get_decoded().get('_auth_user_id')
return {'user': user_id, 'status': 'OK'}
except Session.DoesNotExist:
Expand Down
2 changes: 0 additions & 2 deletions oioioi/oi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,3 @@ def erase_data(self):
self.class_type = 'None'
self.terms_accepted = False
self.save()


Loading

0 comments on commit 7365d97

Please sign in to comment.