Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coalesce i18n_name in python #1408

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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