From 59ab1f38700b6b421a115d46fc14da4d02428437 Mon Sep 17 00:00:00 2001 From: Guanzhong Chen Date: Sun, 31 May 2020 23:24:36 -0400 Subject: [PATCH] Coalesce i18n_name in python (#1408) --- judge/models/problem.py | 3 +-- templates/contest/contest.html | 4 ++-- templates/problem/list.html | 2 +- templates/submission/list.html | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/judge/models/problem.py b/judge/models/problem.py index c2ebf7eb4f..cec1168b9f 100644 --- a/judge/models/problem.py +++ b/judge/models/problem.py @@ -76,8 +76,7 @@ def __init__(self, **kwargs): def add_i18n_name(self, language): queryset = self._clone() alias = unique_together_left_join(queryset, ProblemTranslation, 'problem', 'language', language) - return queryset.annotate(i18n_name=Coalesce(RawSQL('%s.name' % alias, ()), F('name'), - output_field=models.CharField())) + return queryset.annotate(i18n_name=RawSQL('%s.name' % alias, ())) class TranslatedProblemForeignKeyQuerySet(QuerySet): diff --git a/templates/contest/contest.html b/templates/contest/contest.html index 346052c320..06b4343bbf 100644 --- a/templates/contest/contest.html +++ b/templates/contest/contest.html @@ -100,9 +100,9 @@

{{ _ {% if problem.is_public %} - {{ problem.i18n_name }} + {{ problem.i18n_name or problem.name }} {% else %} - {{ problem.i18n_name }} + {{ problem.i18n_name or problem.name }} {% endif %} {{ problem.points|floatformat }}{% if problem.partial %}p{% endif %} diff --git a/templates/problem/list.html b/templates/problem/list.html index cd20dcb8c8..40a7e299cc 100644 --- a/templates/problem/list.html +++ b/templates/problem/list.html @@ -241,7 +241,7 @@ {% endif %} {% endif %} - {{ problem.i18n_name }} + {{ problem.i18n_name or problem.name }} {{ problem.group.full_name }} {% if show_types %} diff --git a/templates/submission/list.html b/templates/submission/list.html index 753730f678..a22903fcfb 100644 --- a/templates/submission/list.html +++ b/templates/submission/list.html @@ -310,7 +310,7 @@ {% for submission in submissions %} - {% with problem_name=show_problem and submission.problem.i18n_name %} + {% with problem_name=show_problem and (submission.problem.i18n_name or submission.problem.name) %} {% include "submission/row.html" %} {% endwith %}