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

add editorial book and sort #1857

Merged
merged 1 commit into from
Feb 24, 2022
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
12 changes: 6 additions & 6 deletions judge/views/contests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.db import IntegrityError
from django.db.models import Case, Count, F, FloatField, IntegerField, Max, Min, Q, Sum, Value, When
from django.db.models import BooleanField, Case, Count, F, FloatField, IntegerField, Max, Min, Q, Sum, Value, When
from django.db.models.expressions import CombinedExpression
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
Expand Down Expand Up @@ -237,11 +237,11 @@ def get_context_data(self, **kwargs):
context = super(ContestDetail, self).get_context_data(**kwargs)
context['contest_problems'] = Problem.objects.filter(contests__contest=self.object) \
.order_by('contests__order').defer('description') \
.annotate(has_public_editorial=Sum(Case(
When(solution__is_public=True, solution__publish_on__lte=timezone.now(), then=1),
default=0,
output_field=IntegerField(),
))) \
.annotate(has_public_editorial=Case(
When(solution__is_public=True, solution__publish_on__lte=timezone.now(), then=True),
default=False,
output_field=BooleanField(),
)) \
.add_i18n_name(self.request.LANGUAGE_CODE)
context['metadata'] = {
'has_public_editorials': any(
Expand Down
18 changes: 10 additions & 8 deletions judge/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.db import transaction
from django.db.models import Case, Count, F, IntegerField, Prefetch, Q, Sum, When
from django.db.models import BooleanField, Case, Count, F, Prefetch, Q, When
from django.db.utils import ProgrammingError
from django.http import Http404, HttpResponse, HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404
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 All @@ -294,6 +294,8 @@ def get_paginator(self, queryset, per_page, orphans=0,
queryset = queryset.order_by(self.order.replace('name', 'i18n_name'), 'id')
elif sort_key == 'group':
queryset = queryset.order_by(self.order + '__name', 'id')
elif sort_key == 'editorial':
queryset = queryset.order_by(self.order.replace('editorial', 'has_public_editorial'), 'id')
elif sort_key == 'solved':
if self.request.user.is_authenticated:
profile = self.request.profile
Expand Down Expand Up @@ -370,13 +372,13 @@ def get_normal_queryset(self):
.values_list('problem__id', flat=True))
if self.show_types:
queryset = queryset.prefetch_related('types')
queryset = queryset.annotate(has_public_editorial=Sum(Case(
When(solution__is_public=True, solution__publish_on__lte=timezone.now(), then=1),
default=0,
output_field=IntegerField(),
)))
queryset = queryset.annotate(has_public_editorial=Case(
When(solution__is_public=True, solution__publish_on__lte=timezone.now(), then=True),
default=False,
output_field=BooleanField(),
))
if self.has_public_editorial:
queryset = queryset.filter(solution__is_public=True, solution__publish_on__lte=timezone.now())
queryset = queryset.filter(has_public_editorial=True)
if self.category is not None:
queryset = queryset.filter(group__id=self.category)
if self.selected_types:
Expand Down
7 changes: 5 additions & 2 deletions templates/problem/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
{% else %}
{% if request.user.is_authenticated %}
<th class="solved">
<a href="{{ sort_links.solved }}"><i class="fa fa-check"></i>{{ sort_order.solved }}
<a href="{{ sort_links.solved }}">
<i class="fa fa-check"></i>{{ sort_order.solved }}
</a>
</th>
{% endif %}
Expand All @@ -233,7 +234,9 @@ <h3>{{ _('Hot problems') }} <i class="fa fa-fire"></i></h3>
<a href="{{ sort_links.ac_rate }}">{{ _('AC %%') }}{{ sort_order.ac_rate }}</a>
</th>
<th class="editorial">
{{ _('Editorial') }}
<a href="{{ sort_links.editorial }}">
<i class="fa fa-book"></i>{{ sort_order.editorial }}
</a>
</th>
<th class="users">
<a href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
Expand Down