From 6b35104b7895af481fbf6a49f218df5dc1c191b0 Mon Sep 17 00:00:00 2001 From: dzhuang Date: Sat, 27 May 2017 12:33:30 +0800 Subject: [PATCH] string_concat deprecated since Django >= 1.11 --- course/admin.py | 3 ++- course/analytics.py | 3 ++- course/auth.py | 4 ++-- course/calendar.py | 4 ++-- course/enrollment.py | 5 ++--- course/exam.py | 5 ++--- course/flow.py | 4 ++-- course/grades.py | 4 ++-- course/models.py | 3 ++- course/page/base.py | 3 +-- course/page/choice.py | 4 ++-- course/page/code.py | 4 ++-- course/page/inline.py | 4 ++-- course/page/text.py | 4 ++-- course/page/upload.py | 4 ++-- course/utils.py | 3 ++- course/validation.py | 4 ++-- course/versioning.py | 3 +-- course/views.py | 3 +-- relate/utils.py | 24 ++++++++++++++++++++++++ requirements.txt | 2 +- 21 files changed, 60 insertions(+), 37 deletions(-) diff --git a/course/admin.py b/course/admin.py index a0256372..ace25a80 100644 --- a/course/admin.py +++ b/course/admin.py @@ -25,7 +25,7 @@ THE SOFTWARE. import six from django.utils.translation import ( - ugettext_lazy as _, string_concat, pgettext) + ugettext_lazy as _, pgettext) from django.contrib import admin from course.models import ( @@ -41,6 +41,7 @@ from course.models import ( GradingOpportunity, GradeChange, InstantMessage, Exam, ExamTicket) from django import forms +from relate.utils import string_concat from course.enrollment import (approve_enrollment, deny_enrollment) from course.constants import ( participation_permission as pperm, diff --git a/course/analytics.py b/course/analytics.py index db42be5c..508e5116 100644 --- a/course/analytics.py +++ b/course/analytics.py @@ -26,7 +26,7 @@ THE SOFTWARE. import six -from django.utils.translation import ugettext as _, pgettext, string_concat +from django.utils.translation import ugettext as _, pgettext from django.shortcuts import ( # noqa render, get_object_or_404, redirect) from django.contrib.auth.decorators import login_required @@ -408,6 +408,7 @@ def make_time_histogram(pctx, flow_id): course=pctx.course, flow_id=flow_id) + from relate.utils import string_concat hist = Histogram( num_log_bins=True, num_bin_title_formatter=( diff --git a/course/auth.py b/course/auth.py index 30da4277..229bcfef 100644 --- a/course/auth.py +++ b/course/auth.py @@ -25,7 +25,7 @@ THE SOFTWARE. """ from typing import cast -from django.utils.translation import ugettext_lazy as _, string_concat +from django.utils.translation import ugettext_lazy as _ from django.shortcuts import ( # noqa render, get_object_or_404, redirect, resolve_url) from django.contrib import messages @@ -61,7 +61,7 @@ from course.constants import ( from course.models import Participation, Course # noqa from accounts.models import User -from relate.utils import StyledForm, StyledModelForm +from relate.utils import StyledForm, StyledModelForm, string_concat from django_select2.forms import ModelSelect2Widget if False: diff --git a/course/calendar.py b/course/calendar.py index 3fbfe8c3..7a06232f 100644 --- a/course/calendar.py +++ b/course/calendar.py @@ -28,7 +28,7 @@ import six from six.moves import range from django.utils.translation import ( - ugettext_lazy as _, pgettext_lazy, string_concat) + ugettext_lazy as _, pgettext_lazy) from django.contrib.auth.decorators import login_required from course.utils import course_view, render_course_page from django.core.exceptions import PermissionDenied, ObjectDoesNotExist @@ -41,7 +41,7 @@ from crispy_forms.layout import Submit import datetime from bootstrap3_datetime.widgets import DateTimePicker -from relate.utils import StyledForm, as_local_time +from relate.utils import StyledForm, as_local_time, string_concat from course.constants import ( participation_permission as pperm, ) diff --git a/course/enrollment.py b/course/enrollment.py index 12adfd97..6e2c9146 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -28,8 +28,7 @@ from six.moves import intern from django.utils.translation import ( ugettext_lazy as _, - pgettext, - string_concat) + pgettext) from django.shortcuts import ( # noqa render, get_object_or_404, redirect) from django.contrib import messages @@ -65,7 +64,7 @@ from course.auth import UserSearchWidget from course.utils import course_view, render_course_page -from relate.utils import StyledForm, StyledModelForm +from relate.utils import StyledForm, StyledModelForm, string_concat from pytools.lex import RE as REBase # noqa diff --git a/course/exam.py b/course/exam.py index 2470061d..6cd666c7 100644 --- a/course/exam.py +++ b/course/exam.py @@ -29,8 +29,7 @@ import six from django.contrib.auth import get_user_model import django.forms as forms from django.utils.translation import ( - ugettext, ugettext_lazy as _, string_concat, - pgettext) + ugettext, ugettext_lazy as _, pgettext) from django.shortcuts import ( # noqa render, get_object_or_404, redirect) from django.core.exceptions import ( # noqa @@ -58,7 +57,7 @@ from course.constants import ( participation_permission as pperm) from course.views import get_now_or_fake_time -from relate.utils import StyledForm +from relate.utils import StyledForm, string_concat # {{{ mypy diff --git a/course/flow.py b/course/flow.py index c7e8bbeb..3d7476d6 100644 --- a/course/flow.py +++ b/course/flow.py @@ -26,7 +26,7 @@ THE SOFTWARE. from django.utils import six from django.utils.translation import ( - ugettext, ugettext_lazy as _, string_concat) + ugettext, ugettext_lazy as _) from django.utils.functional import lazy from django.shortcuts import ( # noqa render, get_object_or_404, redirect) @@ -48,7 +48,7 @@ from crispy_forms.helper import FormHelper from relate.utils import ( StyledForm, local_now, as_local_time, - format_datetime_local) + format_datetime_local, string_concat) from crispy_forms.layout import Submit from django_select2.forms import Select2Widget diff --git a/course/grades.py b/course/grades.py index 012a474c..85233374 100644 --- a/course/grades.py +++ b/course/grades.py @@ -30,7 +30,7 @@ import six from typing import cast from django.utils.translation import ( - ugettext_lazy as _, pgettext_lazy, ugettext, string_concat) + ugettext_lazy as _, pgettext_lazy, ugettext) from django.shortcuts import ( # noqa render, redirect, get_object_or_404) from django.contrib import messages # noqa @@ -43,7 +43,7 @@ from django.utils.timezone import now from django import http from django.urls import reverse -from relate.utils import StyledForm, StyledModelForm +from relate.utils import StyledForm, StyledModelForm, string_concat from crispy_forms.layout import Submit from bootstrap3_datetime.widgets import DateTimePicker diff --git a/course/models.py b/course/models.py index 6b4c0f32..d2de4676 100644 --- a/course/models.py +++ b/course/models.py @@ -33,13 +33,14 @@ from django.utils.timezone import now from django.urls import reverse from django.core.exceptions import ValidationError, ObjectDoesNotExist from django.utils.translation import ( - ugettext_lazy as _, pgettext_lazy, string_concat) + ugettext_lazy as _, pgettext_lazy) from django.core.validators import RegexValidator from django.db.models.signals import post_save from django.dispatch import receiver from django.conf import settings +from relate.utils import string_concat from course.constants import ( # noqa user_status, USER_STATUS_CHOICES, participation_status, PARTICIPATION_STATUS_CHOICES, diff --git a/course/page/base.py b/course/page/base.py index a8259034..4bc5c7eb 100644 --- a/course/page/base.py +++ b/course/page/base.py @@ -30,14 +30,13 @@ import django.forms as forms from course.validation import validate_struct, ValidationError from course.constants import MAX_EXTRA_CREDIT_FACTOR -from relate.utils import StyledForm, Struct +from relate.utils import StyledForm, Struct, string_concat from django.forms import ValidationError as FormValidationError from django.utils.safestring import mark_safe from django.utils.functional import lazy from django.utils.translation import ( ugettext_lazy as _, ugettext, - string_concat, ) from django.utils import translation from django.conf import settings diff --git a/course/page/choice.py b/course/page/choice.py index b59669c8..edaa2ee9 100644 --- a/course/page/choice.py +++ b/course/page/choice.py @@ -29,9 +29,9 @@ from six.moves import range import django.forms as forms from django.utils.safestring import mark_safe from django.utils.translation import ( - ugettext_lazy as _, ugettext, string_concat) + ugettext_lazy as _, ugettext) -from relate.utils import StyledForm +from relate.utils import StyledForm, string_concat from course.page.base import ( AnswerFeedback, PageBaseWithTitle, PageBaseWithValue, markup_to_html) from course.content import remove_prefix diff --git a/course/page/code.py b/course/page/code.py index 7933a236..520fa22f 100644 --- a/course/page/code.py +++ b/course/page/code.py @@ -30,11 +30,11 @@ from course.validation import ValidationError import django.forms as forms from django.core.exceptions import ObjectDoesNotExist from django.utils.html import escape -from django.utils.translation import ugettext as _, string_concat +from django.utils.translation import ugettext as _ from django.utils import translation from django.conf import settings -from relate.utils import StyledForm +from relate.utils import StyledForm, string_concat from course.page.base import ( PageBaseWithTitle, markup_to_html, PageBaseWithValue, PageBaseWithHumanTextFeedback, diff --git a/course/page/inline.py b/course/page/inline.py index 281b1e5c..32ecb334 100644 --- a/course/page/inline.py +++ b/course/page/inline.py @@ -26,13 +26,13 @@ THE SOFTWARE. from django.utils.translation import ( - ugettext_lazy as _, ugettext, string_concat) + ugettext_lazy as _, ugettext) from django.utils.safestring import mark_safe from course.validation import validate_struct, validate_markup, ValidationError from course.content import remove_prefix import django.forms as forms -from relate.utils import Struct, StyledInlineForm +from relate.utils import Struct, StyledInlineForm, string_concat from course.page.base import ( AnswerFeedback, PageBaseWithValue, markup_to_html) diff --git a/course/page/text.py b/course/page/text.py index cb08c1b8..472f4fed 100644 --- a/course/page/text.py +++ b/course/page/text.py @@ -27,11 +27,11 @@ THE SOFTWARE. import six from django.utils.translation import ( - ugettext_lazy as _, ugettext, string_concat) + ugettext_lazy as _, ugettext) from course.validation import validate_struct, ValidationError import django.forms as forms -from relate.utils import StyledForm, Struct +from relate.utils import StyledForm, Struct, string_concat from course.page.base import ( AnswerFeedback, PageBaseWithTitle, PageBaseWithValue, markup_to_html, PageBaseWithHumanTextFeedback, PageBaseWithCorrectAnswer, diff --git a/course/page/upload.py b/course/page/upload.py index 22e018d2..20c3e12c 100644 --- a/course/page/upload.py +++ b/course/page/upload.py @@ -26,7 +26,7 @@ THE SOFTWARE. import django.forms as forms -from django.utils.translation import ugettext as _, ugettext_lazy, string_concat +from django.utils.translation import ugettext as _, ugettext_lazy from course.page.base import ( PageBaseWithTitle, PageBaseWithValue, PageBaseWithHumanTextFeedback, @@ -34,7 +34,7 @@ from course.page.base import ( markup_to_html) from course.validation import ValidationError -from relate.utils import StyledForm +from relate.utils import StyledForm, string_concat from crispy_forms.layout import Layout, Field diff --git a/course/utils.py b/course/utils.py index 122af4fd..b8232ee5 100644 --- a/course/utils.py +++ b/course/utils.py @@ -34,10 +34,11 @@ from django.shortcuts import ( # noqa from django import http from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ( - ugettext as _, string_concat, pgettext_lazy) + ugettext as _, pgettext_lazy) from codemirror import CodeMirrorTextarea, CodeMirrorJavascript +from relate.utils import string_concat from course.content import ( get_course_repo, get_flow_desc, parse_date_spec, get_course_commit_sha) diff --git a/course/validation.py b/course/validation.py index f3b51b1c..f128cb1f 100644 --- a/course/validation.py +++ b/course/validation.py @@ -32,14 +32,14 @@ import sys from django.core.exceptions import ObjectDoesNotExist from django.utils.html import escape from django.utils.translation import ( - ugettext_lazy as _, ugettext, string_concat) + ugettext_lazy as _, ugettext) from course.constants import ( FLOW_SESSION_EXPIRATION_MODE_CHOICES, ATTRIBUTES_FILENAME, participation_permission as pperm) from course.content import get_repo_blob -from relate.utils import Struct +from relate.utils import Struct, string_concat # {{{ mypy diff --git a/course/versioning.py b/course/versioning.py index c392c7da..2a78565f 100644 --- a/course/versioning.py +++ b/course/versioning.py @@ -37,14 +37,13 @@ from django.utils.translation import ( ugettext, pgettext, pgettext_lazy, - string_concat, ) from django_select2.forms import Select2Widget from bootstrap3_datetime.widgets import DateTimePicker from django.db import transaction -from relate.utils import StyledForm, StyledModelForm +from relate.utils import StyledForm, StyledModelForm, string_concat from crispy_forms.layout import Submit from course.models import ( diff --git a/course/views.py b/course/views.py index 6f1f14cd..5128d3e2 100644 --- a/course/views.py +++ b/course/views.py @@ -40,7 +40,6 @@ from django.utils import six from django.utils.translation import ( ugettext_lazy as _, ugettext, - string_concat, pgettext, pgettext_lazy, ) @@ -55,7 +54,7 @@ from django.views.decorators.cache import cache_control from crispy_forms.layout import Submit, Layout, Div -from relate.utils import StyledForm, StyledModelForm +from relate.utils import StyledForm, StyledModelForm, string_concat from bootstrap3_datetime.widgets import DateTimePicker from course.auth import get_pre_impersonation_user diff --git a/relate/utils.py b/relate/utils.py index 1c93bd93..1c862b25 100644 --- a/relate/utils.py +++ b/relate/utils.py @@ -36,6 +36,30 @@ from typing import Union if False: from typing import Text, List, Dict, Tuple, Optional, Any # noqa +# {{{ string_concat compatibility for Django >= 1.11 + +try: + from django.utils.text import format_lazy +except ImportError: + def _format_lazy(format_string, *args, **kwargs): + # type(Text, *Any, **Any) -> Text + """ + Apply str.format() on 'format_string' where format_string, args, + and/or kwargs might be lazy. + """ + return format_string.format(*args, **kwargs) + + from django.utils.functional import lazy + format_lazy = lazy(_format_lazy, str) + +try: + from django.utils.translation import string_concat +except ImportError: + def string_concat(*strings): + return format_lazy("{}" * len(strings), *strings) + +# }}} + class StyledForm(forms.Form): def __init__(self, *args, **kwargs): diff --git a/requirements.txt b/requirements.txt index b79796bb..036f50f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django>=1.10,<1.11 +django>=1.10,<1.12 # Automatically renders Django forms in a pretty, Bootstrap-compatible way. django-crispy-forms>=1.5.1 -- GitLab