Skip to content

Commit

Permalink
Coalesce i18n_name in python (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 authored Jun 1, 2020
1 parent 9b8e3d7 commit 158fa06
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 @@ -94,9 +94,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 @@ -275,7 +275,7 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
{% 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 @@ -359,7 +359,7 @@ <h3>{{ _('Statistics') }} <i class="fa fa-pie-chart"></i></h3>
{% set profile_id = request.profile.id if request.user.is_authenticated else 0 %}
{% for submission in submissions %}
<div 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 %}
</div>
Expand Down

0 comments on commit 158fa06

Please sign in to comment.