Skip to content

Commit

Permalink
Coalesce i18n_name in python (DMOJ#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 authored and outloudvi committed Sep 28, 2020
1 parent 3b81263 commit 59ab1f3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions judge/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions templates/contest/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ <h2 style="margin-bottom: 0.2em"><i class="fa fa-fw fa-question-circle"></i>{{ _
<tr>
<td>
{% if problem.is_public %}
<a href="{{ url('problem_detail', problem.code) }}">{{ problem.i18n_name }}</a>
<a href="{{ url('problem_detail', problem.code) }}">{{ problem.i18n_name or problem.name }}</a>
{% else %}
{{ problem.i18n_name }}
{{ problem.i18n_name or problem.name }}
{% endif %}
</td>
<td>{{ problem.points|floatformat }}{% if problem.partial %}p{% endif %}</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/problem/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
{% endif %}
{% endif %}
<td class="problem">
<a href="{{ url('problem_detail', problem.code) }}">{{ problem.i18n_name }}</a>
<a href="{{ url('problem_detail', problem.code) }}">{{ problem.i18n_name or problem.name }}</a>
</td>
<td class="category">{{ problem.group.full_name }}</td>
{% if show_types %}
Expand Down
2 changes: 1 addition & 1 deletion templates/submission/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
<tbody>
{% for submission in submissions %}
<tr class="submission-row" id="{{ submission.id }}">
{% 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 %}
</tr>
Expand Down

0 comments on commit 59ab1f3

Please sign in to comment.