Skip to content

Commit

Permalink
Add editorial column and filtering
Browse files Browse the repository at this point in the history
The problem page now has an editorial column. The search form can now be 
used to only show problems with an editorial.

The only extraneous change is adding a method to `Problem`, 
`has_public_editorial`.
  • Loading branch information
Riolku committed Feb 21, 2022
1 parent 0516433 commit 978dbc5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions judge/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def is_accessible_by(self, user, skip_contest_problem_check=False):
def is_subs_manageable_by(self, user):
return user.is_staff and user.has_perm('judge.rejudge_submission') and self.is_editable_by(user)

def has_public_editorial(self):
return Solution.objects.filter(problem=self, publish_on__lte=timezone.now(), is_public=True).exists()

@classmethod
def get_visible_problems(cls, user):
# Do unauthenticated check here so we can skip authentication checks later on.
Expand Down
15 changes: 13 additions & 2 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.shortcuts import get_object_or_404
from django.template.loader import get_template
from django.urls import reverse
from django.utils import translation
from django.utils import timezone, translation
from django.utils.functional import cached_property
from django.utils.html import escape, format_html
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -272,7 +272,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
template_name = 'problem/list.html'
paginate_by = 50
sql_sort = frozenset(('points', 'ac_rate', 'user_count', 'code'))
manual_sort = frozenset(('name', 'group', 'solved', 'type'))
manual_sort = frozenset(('name', 'group', 'solved', 'type', 'editorial'))
all_sorts = sql_sort | manual_sort
default_desc = frozenset(('points', 'ac_rate', 'user_count'))
default_sort = 'code'
Expand Down Expand Up @@ -309,6 +309,12 @@ def _solved_sort_order(problem):

queryset = list(queryset)
queryset.sort(key=_solved_sort_order, reverse=self.order.startswith('-'))
elif sort_key == 'editorial':
def _editorial_sort_order(problem):
return int(problem.has_public_editorial())

queryset = list(queryset)
queryset.sort(key=_editorial_sort_order, reverse=self.order.startswith('-'))
elif sort_key == 'type':
if self.show_types:
queryset = list(queryset)
Expand Down Expand Up @@ -370,6 +376,9 @@ def get_normal_queryset(self):
.values_list('problem__id', flat=True))
if self.show_types:
queryset = queryset.prefetch_related('types')
queryset = queryset.select_related('solution').defer('solution__content')
if self.has_public_editorial:
queryset = queryset.filter(solution__is_public=True, solution__publish_on__lte=timezone.now())
if self.category is not None:
queryset = queryset.filter(group__id=self.category)
if self.selected_types:
Expand Down Expand Up @@ -400,6 +409,7 @@ def get_context_data(self, **kwargs):
context = super(ProblemList, self).get_context_data(**kwargs)
context['hide_solved'] = 0 if self.in_contest else int(self.hide_solved)
context['show_types'] = 0 if self.in_contest else int(self.show_types)
context['has_public_editorial'] = 0 if self.in_contest else int(self.has_public_editorial)
context['full_text'] = 0 if self.in_contest else int(self.full_text)
context['category'] = self.category
context['categories'] = ProblemGroup.objects.all()
Expand Down Expand Up @@ -451,6 +461,7 @@ def setup_problem_list(self, request):
self.hide_solved = self.GET_with_session(request, 'hide_solved')
self.show_types = self.GET_with_session(request, 'show_types')
self.full_text = self.GET_with_session(request, 'full_text')
self.has_public_editorial = self.GET_with_session(request, 'has_public_editorial')

self.search_query = None
self.category = None
Expand Down
8 changes: 8 additions & 0 deletions resources/problem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ ul.problem-list {
color: orange;
}

.has-editorial-color {
color: #44AD41;
}

.no-editorial-color {
color: #DE2121;
}

.submissions-left {
color: black;
font-weight: 600;
Expand Down
12 changes: 12 additions & 0 deletions templates/problem/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
<th class="ac-rate">
<a href="{{ sort_links.ac_rate }}">{{ _('AC %%') }}{{ sort_order.ac_rate }}</a>
</th>
<th class="editorial">
<a href="{{ sort_links.editorial }}">{{ _('Editorial') }}{{ sort_order.editorial }}</a>
</th>
<th class="users">
<a href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
</th>
Expand Down Expand Up @@ -287,6 +290,15 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
{% if not request.in_contest %}
<td class="ac-rate">{{ problem.ac_rate|floatformat(1) }}%</td>
{% endif %}
{% if problem.has_public_editorial() %}
<td editorial="1">
<i class="has-editorial-color fa fa-check-circle"></i>
</td>
{% else %}
<td editorial="0">
<i class="no-editorial-color fa fa-minus-circle"></i>
</td>
{% endif %}
<td class="users">
<a href="{{ url('ranked_submissions', problem.code) }}">
{% if not request.in_contest or not hide_contest_scoreboard %}
Expand Down
7 changes: 6 additions & 1 deletion templates/problem/search-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ <h3>{{ _('Problem search') }} <i class="fa fa-search"></i>
<label for="hide_solved">{{ _('Hide solved problems') }}</label>
</div>
{% endif %}
<div>
<input id="has_public_editorial" type="checkbox" name="has_public_editorial" value="1"
{% if has_public_editorial %} checked{% endif %}>
<label for="has_public_editorial">{{ _('Has editorial') }}</label>
</div>
<div>
<input id="show_types" type="checkbox" name="show_types" value="1"
{% if show_types %} checked{% endif %}>
Expand Down Expand Up @@ -65,4 +70,4 @@ <h3>{{ _('Problem search') }} <i class="fa fa-search"></i>
</div>
</form>
</div>
</div>
</div>

0 comments on commit 978dbc5

Please sign in to comment.