Skip to content

Commit

Permalink
SIO-2426 Add django 2.1 support
Browse files Browse the repository at this point in the history
Added 1.11 compatible changes.
Change load staticfiles to load static in templates.
Removed use of django.utils.translation.string_concat().
Updated is_safe_url to new standard.
Few more string enforecements.
Added temporary workaround for sqlite change.

Change-Id: I9b451ebe22f4edad44a06c412bedb94611129bf0
  • Loading branch information
badochov committed May 10, 2021
1 parent 250f38d commit 713b61a
Show file tree
Hide file tree
Showing 27 changed files with 35 additions and 33 deletions.
9 changes: 4 additions & 5 deletions oioioi/base/signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ def set_first_view_after_logging_flag(sender, user, request, **kwargs):
request.session['first_view_after_logging'] = True


# Workaround for https://code.djangoproject.com/ticket/29182
# TODO: delete after upgrade to Django 2.1+
assert django.VERSION < (2, 1, 5)


@receiver(connection_created)
def db_connection_callback(sender, connection, **kwargs):
if connection.vendor == 'sqlite':
connection.cursor().execute('PRAGMA legacy_alter_table = ON')

"""https://code.djangoproject.com/ticket/30023"""
"""Globally disabling foreign key constraint checking."""
connection.cursor().execute('PRAGMA foreign_keys = OFF')
2 changes: 1 addition & 1 deletion oioioi/base/templates/api-key.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-with-menu.html" %}
{% load i18n staticfiles simple_filters %}
{% load i18n static simple_filters %}

{% block title %}{% trans "API token" %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion oioioi/base/templates/ingredients/head-favicon.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% load staticfiles %}
{% load static %}

<link rel="shortcut icon" href="{% static "favicon.ico" %}"/>
2 changes: 1 addition & 1 deletion oioioi/base/templates/ingredients/markdown-editor.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}
{% load static %}

<link charset="utf-8" rel="stylesheet" href="{{ STATIC_URL }}bootstrap-markdown/css/bootstrap-markdown.min.css" />
<link charset="utf-8" rel="stylesheet" href="{{ STATIC_URL }}icofont/css/icofont.css" />
Expand Down
2 changes: 1 addition & 1 deletion oioioi/base/templates/ingredients/translation-formset.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n staticfiles compress %}
{% load i18n static compress %}
{% get_current_language as LANGUAGE_CODE %}

<div id="translation-formset" class="clearfix">
Expand Down
2 changes: 1 addition & 1 deletion oioioi/base/utils/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def safe_redirect(request, url, fallback='index'):
else:
next_page = reverse(fallback)
else:
if url and is_safe_url(url=url, host=request.get_host()):
if url and is_safe_url(url=url, allowed_hosts=request.get_host()):
next_page = url
else:
next_page = reverse(fallback)
Expand Down
2 changes: 1 addition & 1 deletion oioioi/contests/templates/contests/submit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-with-menu.html" %}
{% load i18n staticfiles simple_filters %}
{% load i18n static simple_filters %}

{% block title %}{% trans "Submit solution" %}{% endblock %}

Expand Down
5 changes: 4 additions & 1 deletion oioioi/forum/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import string_concat
from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy

Expand All @@ -12,6 +12,9 @@
from oioioi.contests.utils import is_contest_admin
from oioioi.forum.models import Ban, Category, Forum, Post, Thread

def string_concat(*strings):
"""https://docs.djangoproject.com/en/3.2/releases/1.11/#deprecated-features-1-11"""
return format_lazy('{}' * len(strings), *strings)

def make_list_elem(elem, text=None):
if not text:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n staticfiles %}
{% load i18n static %}

<script src="{{ notif_server_url }}socket.io/socket.io.js"></script>
<script>
Expand Down
2 changes: 1 addition & 1 deletion oioioi/portals/templates/portals/portals_main_page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load i18n simple_tags pagination_tags tag staticfiles node_language_version %}
{% load i18n simple_tags pagination_tags tag static node_language_version %}

{% block title %}{% trans "Portals" %} {% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion oioioi/problems/templates/problems/problemset-source.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n staticfiles simple_filters %}
{% load i18n static simple_filters %}

<p>
<a role="button" class="btn btn-default" href="{% url 'problemset_main' %}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "problems/problemset/base.html" %}
{% load i18n pagination_tags tag statistics_tags staticfiles %}
{% load i18n pagination_tags tag statistics_tags static %}

{% block main_content %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "problems/problemset/base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block title %}{{ problem }} - {% trans "Problemset" %}{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "problems/problemset/base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block main_content %}

Expand Down
2 changes: 1 addition & 1 deletion oioioi/programs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def extract_code(show_response):
preStart = show_response.content.find(b'<pre>', preFirst) + len(b'<pre>')
preEnd = show_response.content.find(b'</pre>', preFirst)
# Get substring and strip tags.
show_response.content = strip_tags(show_response.content[preStart:preEnd])
show_response.content = strip_tags(six.ensure_text(show_response.content[preStart:preEnd], errors="replace"))


class SubmitFileMixin(SubmitMixin):
Expand Down
2 changes: 1 addition & 1 deletion oioioi/questions/templates/questions/add.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base-with-menu.html" %}

{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block scripts %}
{{ block.super }}
Expand Down
6 changes: 3 additions & 3 deletions oioioi/rankings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create_score(username, score):
def get_url_for_user(username):
get = QueryDict('', mutable=True)
get['user'] = username
get['page'] = 1
get['page'] = '1'
return url + '?' + get.urlencode()

def get_url_found_user(user, page):
Expand Down Expand Up @@ -117,7 +117,7 @@ def get_url_found_user(user, page):
user = users[i]
response = self.client.get(get_url_for_user(user.username))
# On which page should the user be?
page = ((number_of_users - 1 - i) // per_page) + 1
page = str(((number_of_users - 1 - i) // per_page) + 1)
self.assertRedirects(response, get_url_found_user(user, page))

# Login as someone who is in the ranking
Expand All @@ -132,7 +132,7 @@ def get_url_found_user(user, page):

# Test if users[0] can find himself
response = self.client.get(get_url_for_user(users[user_num].username))
page = ((number_of_users - user_num) // per_page) + 1
page = str(((number_of_users - user_num) // per_page) + 1)
self.assertRedirects(response, get_url_found_user(users[user_num], page))

for i in range(number_of_users):
Expand Down
2 changes: 1 addition & 1 deletion oioioi/rankings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ranking_view(request, key=None):
found_page = ((found_pos - 1) // users_per_page) + 1
get_dict = request.GET.copy()
get_dict.pop('user')
get_dict['page'] = found_page
get_dict['page'] = str(found_page)
return redirect(
request.path + '?' + get_dict.urlencode() + '#' + str(user.id)
)
Expand Down
2 changes: 1 addition & 1 deletion oioioi/simpleui/templates/simpleui/contest/contest.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "simpleui/simpleui-base.html" %}
{% load i18n staticfiles compress %}
{% load i18n static compress %}

{% block title %}{% trans "Contest dashboard" %}{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "simpleui/simpleui-base.html" %}
{% load i18n static staticfiles compress %}
{% load i18n static compress %}

{% block title %}{% trans "User dashboard" %}{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "simpleui/simpleui-base.html" %}
{% load i18n compress staticfiles %}
{% load i18n compress static %}

{% block title %}{% trans "Problem settings" %}{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-with-menu.html" %}
{% load i18n staticfiles %}
{% load i18n static %}
{% block title %}{% trans "Submitting solutions from terminal" %}{% endblock %}

{% block main-content %}
Expand Down
2 changes: 1 addition & 1 deletion oioioi/szkopul/templates/ingredients/head-favicon.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% load staticfiles %}
{% load static %}

<link rel="shortcut icon" href="{% static "szkopul/favicon.ico" %}"/>
2 changes: 1 addition & 1 deletion oioioi/szkopul/templates/ingredients/main-page-bottom.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n staticfiles newsfeed %}
{% load i18n static newsfeed %}

<h3>{% trans "News" %}</h3>
<p>{% newsfeed %}</p>
Expand Down
2 changes: 1 addition & 1 deletion oioioi/szkopul/templates/ingredients/navbar-logo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}
{% load static %}

<a class="oioioi-navbar__brand {% if always_visible %}oioioi-navbar__brand--always{% endif %}" href="{% url 'index' contest_id=None %}">
<img src="{% static "szkopul/napis.png" %}" alt="SZKOpuł">
Expand Down
2 changes: 1 addition & 1 deletion oioioi/szkopul/templates/main-page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}

{% load i18n staticfiles contest_selection newsfeed %}
{% load i18n static contest_selection newsfeed %}
{% get_current_language as LANGUAGE_CODE %}

{% block left-navbar %}
Expand Down
2 changes: 1 addition & 1 deletion oioioi/testrun/templates/testrun/submit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base-with-menu.html" %}
{% load i18n staticfiles simple_filters %}
{% load i18n static simple_filters %}

{% block title %}{% trans "Submit solution" %} - {% trans "Test run" %}{% endblock %}

Expand Down

0 comments on commit 713b61a

Please sign in to comment.