Skip to content

Commit

Permalink
Add a table in problem view to switch problems (#361)
Browse files Browse the repository at this point in the history
* Add a table to switch to problems

* optimize query

---------

Co-authored-by: Le Duy Thuc <[email protected]>
  • Loading branch information
jalsol and leduythuccs authored Dec 5, 2023
1 parent 5567fac commit 8aa4d53
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def get_context_data(self, **kwargs):
context['submissions_left'] = max(contest_problem.max_submissions -
get_contest_submission_count(self.object, user.profile,
user.profile.current_contest.virtual), 0)
context['contest_problems'] = Problem.objects.filter(contests__contest=contest_problem.contest) \
.order_by('contests__order').only('code')

context['available_judges'] = Judge.objects.filter(online=True, problems=self.object)
context['show_languages'] = self.object.allowed_languages.count() != Language.objects.count()
Expand Down
40 changes: 39 additions & 1 deletion templates/problem/problem.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
min-width: 12.5em;
}

#problem-types, #allowed-langs, #available-judges {
#problem-types, #allowed-langs, #available-judges, #contest-problems-list {
padding-top: 1em;
}

Expand All @@ -51,6 +51,15 @@
position: absolute;
left: -999em;
}

.highlighted {
background: #f7ef81;
}

td a {
display: block;
width: 100%;
}
</style>
{% endblock %}

Expand Down Expand Up @@ -322,6 +331,35 @@ <h2 style="display: inline-block">{{ title }}</h2>
</div>
</div>
{% endif %}

{% set contest = contest_problem.contest %}
{% if contest_problems %}
<div id="contest-problems-list">
<div class="toggle open unselectable">
<i class="fa fa-chevron-right fa-fw"></i>{{ _('Problems') }}
</div>
<div class="toggled">
<table class="table striped">
<tbody>
{% for contest_problem in contest_problems %}
<tr>
{% if problem.code == contest_problem.code %}
<td class="highlighted" style="text-align: center">
{% else %}
<td style="text-align: center">
{% endif %}
<a href="{{ url('problem_detail', contest_problem.code) }}">
{{contest.get_label_for_problem(loop.index0)}}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}

{% if problem.is_editable_by(request.user) %}
<div id="available-judges">
<i class="fa fa-database fa-fw"></i><span
Expand Down

0 comments on commit 8aa4d53

Please sign in to comment.