Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Miscellaneous changes #151

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions oioioi/acm/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import re
from datetime import datetime # pylint: disable=E0611
from datetime import datetime, timezone

from django.urls import reverse
from django.utils.timezone import utc

from oioioi.base.tests import TestCase, fake_timezone_now
from oioioi.contests.models import Contest
Expand Down Expand Up @@ -53,20 +52,20 @@ def test_ranking_view(self):

# trial round begins at 11:00, ends at 16:00, results are available
# at 19:00
with fake_timezone_now(datetime(2013, 12, 13, 10, 59, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 13, 10, 59, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
for task in ['trial', 'A', 'sum', 'test']:
self.assertActiveTaskNotIn(task, content)

with fake_timezone_now(datetime(2013, 12, 13, 11, 30, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 13, 11, 30, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertActiveTaskIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertActiveTaskNotIn(task, content)

with fake_timezone_now(datetime(2013, 12, 13, 17, 0, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 13, 17, 0, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertInactiveTaskIn('trial', content)
Expand All @@ -75,52 +74,52 @@ def test_ranking_view(self):

# round 1 starts at 20:40, ends at 01:40, results are available at
# 09:00
with fake_timezone_now(datetime(2013, 12, 14, 20, 39, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 14, 20, 39, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertInactiveTaskIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertInactiveTaskNotIn(task, content)

with fake_timezone_now(datetime(2013, 12, 14, 20, 40, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 14, 20, 40, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertActiveTaskNotIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertActiveTaskIn(task, content)
self.assertNotContains(response, 'The ranking is frozen.')

with fake_timezone_now(datetime(2013, 12, 15, 1, 0, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 15, 1, 0, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertActiveTaskNotIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertActiveTaskIn(task, content)
self.assertContains(response, 'The ranking is frozen.')

with fake_timezone_now(datetime(2013, 12, 15, 7, 0, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 15, 7, 0, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertInactiveTaskNotIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertInactiveTaskIn(task, content)
self.assertContains(response, 'The ranking is frozen.')

with fake_timezone_now(datetime(2013, 12, 15, 9, 0, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 15, 9, 0, tzinfo=timezone.utc)):
response = self.client.get(url)
content = response.content.decode('utf-8')
self.assertInactiveTaskNotIn('trial', content)
for task in ['A', 'sum', 'test']:
self.assertInactiveTaskIn(task, content)
self.assertNotContains(response, 'The ranking is frozen.')

with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertContains(response, 'data-username="test_user"', count=2)

self.assertTrue(self.client.login(username='test_admin'))

with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=utc)):
with fake_timezone_now(datetime(2013, 12, 15, 0, 40, tzinfo=timezone.utc)):
response = self.client.get(csv_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '\n', count=4)
Expand Down
2 changes: 1 addition & 1 deletion oioioi/balloons/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class BalloonsDeliveryAccessDataAdminMixin(object):

def __init__(self, *args, **kwargs):
super(BalloonsDeliveryAccessDataAdminMixin, self).__init__(*args, **kwargs)
self.inlines = self.inlines + [BalloonsDeliveryAccessDataInline]
self.inlines = self.inlines + (BalloonsDeliveryAccessDataInline,)


ContestAdmin.mix_in(BalloonsDeliveryAccessDataAdminMixin)
9 changes: 4 additions & 5 deletions oioioi/balloons/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime # pylint: disable=E0611
from datetime import datetime, timezone

from django.contrib.admin.utils import quote
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils.timezone import utc

from oioioi.balloons.models import BalloonDelivery, BalloonsDeliveryAccessData
from oioioi.base.tests import TestCase, fake_time
Expand Down Expand Up @@ -190,11 +189,11 @@ def test_setting_delivered_status(self):

def test_cookie_expiry_date(self):
url = reverse('balloons_delivery_panel', kwargs=self.c_kwargs)
with fake_time(datetime(2012, 8, 5, 0, 5, tzinfo=utc)):
with fake_time(datetime(2012, 8, 5, 0, 5, tzinfo=timezone.utc)):
self._generate_link_and_set_cookie()
with fake_time(datetime(2012, 8, 12, 0, 4, tzinfo=utc)):
with fake_time(datetime(2012, 8, 12, 0, 4, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
with fake_time(datetime(2012, 8, 12, 0, 6, tzinfo=utc)):
with fake_time(datetime(2012, 8, 12, 0, 6, tzinfo=timezone.utc)):
response = self.client.get(url)
self.assertEqual(response.status_code, 403)
2 changes: 1 addition & 1 deletion oioioi/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def has_delete_permission(self, request, obj=None):
class UserWithConsentsAdminMixin(object):
def __init__(self, *args, **kwargs):
super(UserWithConsentsAdminMixin, self).__init__(*args, **kwargs)
self.inlines += [ConsentsInline]
self.inlines += (ConsentsInline,)


OioioiUserAdmin.mix_in(UserWithConsentsAdminMixin)
6 changes: 3 additions & 3 deletions oioioi/base/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db import models
from django.db.models.fields import BLANK_CHOICE_DASH, exceptions
from django.forms import ValidationError
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -64,13 +64,13 @@ def get_choices(
lst = [
(
getattr(x, self.remote_field.get_related_field().attname),
smart_text(x),
smart_str(x),
)
for x in rel_model._default_manager.complex_filter(limit_choices_to)
]
else:
lst = [
(x._get_pk_val(), smart_text(x))
(x._get_pk_val(), smart_str(x))
for x in rel_model._default_manager.complex_filter(limit_choices_to)
]
return first_choice + lst
Expand Down
2 changes: 1 addition & 1 deletion oioioi/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
auditLogger = logging.getLogger(__name__ + ".audit")

# Sender will be equal to the form that was completed
PreferencesSaved = django.dispatch.Signal(providing_args=['user'])
PreferencesSaved = django.dispatch.Signal()


class Consents(models.Model):
Expand Down
12 changes: 6 additions & 6 deletions oioioi/base/templates/two_factor/core/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "two_factor/_base_focus.html" %}
{% load i18n two_factor %}
{% load i18n %}

{% block content %}
{% comment %}
Expand All @@ -19,17 +19,17 @@ <h1 class="mb-0">{% block title %}{% trans "Log in" %}{% endblock %}</h1>
<div class="card-body">
{% if wizard.steps.current == 'token' %}
{% if device.method == 'call' %}
<p>{% blocktrans %}We are calling your phone right now, please enter the
<p>{% blocktrans trimmed %}We are calling your phone right now, please enter the
digits you hear.{% endblocktrans %}</p>
{% elif device.method == 'sms' %}
<p>{% blocktrans %}We sent you a text message, please enter the tokens we
<p>{% blocktrans trimmed %}We sent you a text message, please enter the tokens we
sent.{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans %}Please enter the tokens generated by your token
<p>{% blocktrans trimmed %}Please enter the tokens generated by your token
generator.{% endblocktrans %}</p>
{% endif %}
{% elif wizard.steps.current == 'backup' %}
<p>{% blocktrans %}Use this form for entering backup tokens for logging in.
<p>{% blocktrans trimmed %}Use this form for entering backup tokens for logging in.
These tokens have been generated for you to print and keep safe. Please
enter one of these backup tokens to login to your account.{% endblocktrans %}</p>
{% endif %}
Expand All @@ -46,7 +46,7 @@ <h1 class="mb-0">{% block title %}{% trans "Log in" %}{% endblock %}</h1>
{% for other in other_devices %}
<button name="challenge_device" value="{{ other.persistent_id }}"
class="btn btn-outline-secondary btn-block" type="submit">
{{ other|device_action }}
{{ other.generate_challenge_button_title }}
</button>
{% endfor %}</p>
{% endif %}
Expand Down
9 changes: 6 additions & 3 deletions oioioi/celery/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oioioi.default_settings')

from django.conf import settings # noqa

app = Celery('oioioi')

from django.conf import settings

CELERY_CONFIG = settings.CELERY or {}

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.config_from_object('oioioi.celery.celery:CELERY_CONFIG')

app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
5 changes: 2 additions & 3 deletions oioioi/clock/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import calendar
import time
from datetime import datetime # pylint: disable=E0611
from datetime import datetime, timezone

from dateutil.parser import parse as parse_date
from django.contrib.auth.models import User
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.timezone import utc

from oioioi.base.tests import TestCase
from oioioi.contests.current_contest import ContestMode
Expand Down Expand Up @@ -67,7 +66,7 @@ def test_countdown_with_extended_rounds(self):
def test_admin_time(self):
self.assertTrue(self.client.login(username='test_admin'))
session = self.client.session
session['admin_time'] = datetime(2012, 12, 12, tzinfo=utc).isoformat()
session['admin_time'] = datetime(2012, 12, 12, tzinfo=timezone.utc).isoformat()
session.save()
response = self.client.get(reverse('get_status')).json()
self.assertTrue(response['is_admin_time_set'])
Expand Down
2 changes: 1 addition & 1 deletion oioioi/complaints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ComplaintsAdminMixin(object):

def __init__(self, *args, **kwargs):
super(ComplaintsAdminMixin, self).__init__(*args, **kwargs)
self.inlines = self.inlines + [ComplaintsConfigInline]
self.inlines = self.inlines + (ComplaintsConfigInline,)


ContestAdmin.mix_in(ComplaintsAdminMixin)
15 changes: 7 additions & 8 deletions oioioi/complaints/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from datetime import datetime # pylint: disable=E0611
from datetime import datetime, timezone

from django.contrib.auth.models import User
from django.core import mail
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.timezone import utc

from oioioi.base.tests import TestCase, fake_time
from oioioi.complaints.models import ComplaintsConfig
Expand All @@ -24,7 +23,7 @@ def test_making_complaint(self):
p = Participant(contest=contest, user=user, status='ACTIVE')
p.save()

with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
with fake_time(datetime(2012, 8, 11, tzinfo=timezone.utc)):
self.assertTrue(self.client.login(username='test_user'))
response = self.client.post(
reverse('add_complaint', kwargs={'contest_id': contest.id}),
Expand All @@ -36,24 +35,24 @@ def test_making_complaint(self):
cconfig = ComplaintsConfig(
contest=contest,
enabled=True,
start_date=datetime(2012, 8, 10, tzinfo=utc),
end_date=datetime(2012, 8, 12, tzinfo=utc),
start_date=datetime(2012, 8, 10, tzinfo=timezone.utc),
end_date=datetime(2012, 8, 12, tzinfo=timezone.utc),
)
cconfig.save()

with fake_time(datetime(2012, 8, 9, tzinfo=utc)):
with fake_time(datetime(2012, 8, 9, tzinfo=timezone.utc)):
response = self.client.get(
reverse('add_complaint', kwargs={'contest_id': contest.id})
)
self.assertEqual(response.status_code, 403)

with fake_time(datetime(2012, 8, 13, tzinfo=utc)):
with fake_time(datetime(2012, 8, 13, tzinfo=timezone.utc)):
response = self.client.get(
reverse('add_complaint', kwargs={'contest_id': contest.id})
)
self.assertEqual(response.status_code, 403)

with fake_time(datetime(2012, 8, 11, tzinfo=utc)):
with fake_time(datetime(2012, 8, 11, tzinfo=timezone.utc)):
response = self.client.post(
reverse('add_complaint', kwargs={'contest_id': contest.id}),
{'complaint': "I am innocent! It is your fault!"},
Expand Down
2 changes: 1 addition & 1 deletion oioioi/contestexcl/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ContestAdminWithExclusivenessInlineMixin(object):

def __init__(self, *args, **kwargs):
super(ContestAdminWithExclusivenessInlineMixin, self).__init__(*args, **kwargs)
self.inlines = self.inlines + [ExclusivenessConfigInline]
self.inlines = self.inlines + (ExclusivenessConfigInline,)

def _warn_on_contestexcl_overlap(self, request, ex_confs):
for obj in ex_confs:
Expand Down
Loading