Add contest sort (DMOJ)
This commit is contained in:
parent
580b67829c
commit
70d81ad664
2 changed files with 18 additions and 7 deletions
|
@ -39,7 +39,8 @@ from judge.utils.opengraph import generate_opengraph
|
|||
from judge.utils.problems import _get_result_data
|
||||
from judge.utils.ranker import ranker
|
||||
from judge.utils.stats import get_bar_chart, get_pie_chart, get_histogram
|
||||
from judge.utils.views import DiggPaginatorMixin, SingleObjectFormView, TitleMixin, generic_message
|
||||
from judge.utils.views import DiggPaginatorMixin, QueryStringSortMixin, SingleObjectFormView, TitleMixin, \
|
||||
generic_message
|
||||
from judge.widgets import HeavyPreviewPageDownWidget
|
||||
|
||||
__all__ = ['ContestList', 'ContestDetail', 'ContestRanking', 'ContestJoin', 'ContestLeave', 'ContestCalendar',
|
||||
|
@ -64,12 +65,15 @@ class ContestListMixin(object):
|
|||
return Contest.get_visible_contests(self.request.user)
|
||||
|
||||
|
||||
class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
||||
class ContestList(QueryStringSortMixin, DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
||||
model = Contest
|
||||
paginate_by = 20
|
||||
template_name = 'contest/list.html'
|
||||
title = gettext_lazy('Contests')
|
||||
context_object_name = 'past_contests'
|
||||
all_sorts = frozenset(('name', 'user_count', 'start_time'))
|
||||
default_desc = frozenset(('name', 'user_count'))
|
||||
default_sort = '-start_time'
|
||||
first_page_href = None
|
||||
|
||||
@cached_property
|
||||
|
@ -90,7 +94,7 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
|||
|
||||
def _get_queryset(self):
|
||||
queryset = super(ContestList, self).get_queryset() \
|
||||
.order_by('-start_time', 'key').prefetch_related('tags', 'organizations', 'authors', 'curators', 'testers')
|
||||
.prefetch_related('tags', 'organizations', 'authors', 'curators', 'testers')
|
||||
|
||||
if 'contest' in self.request.GET:
|
||||
self.contest_query = query = ' '.join(self.request.GET.getlist('contest')).strip()
|
||||
|
@ -103,7 +107,7 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
|||
return queryset
|
||||
|
||||
def get_queryset(self):
|
||||
return self._get_queryset().filter(end_time__lt=self._now)
|
||||
return self._get_queryset().order_by(self.order, 'key').filter(end_time__lt=self._now)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ContestList, self).get_context_data(**kwargs)
|
||||
|
@ -124,7 +128,8 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
|||
active.append(participation)
|
||||
present.remove(participation.contest)
|
||||
|
||||
active.sort(key=attrgetter('end_time'))
|
||||
active.sort(key=attrgetter('end_time', 'key'))
|
||||
present.sort(key=attrgetter('end_time', 'key'))
|
||||
future.sort(key=attrgetter('start_time'))
|
||||
context['active_participations'] = active
|
||||
context['current_contests'] = present
|
||||
|
@ -137,6 +142,8 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
|
|||
context['page_suffix'] = suffix = (
|
||||
'?' + self.request.GET.urlencode()) if self.request.GET else ''
|
||||
context['first_page_href'] = (self.first_page_href or '.') + suffix
|
||||
context.update(self.get_sort_context())
|
||||
context.update(self.get_sort_paginate_context())
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
@ -362,8 +362,12 @@
|
|||
<table class="contest-list table striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:90%">{{ _('Contest') }}</th>
|
||||
<th>{{ _('Users') }}</th>
|
||||
<th style="width:90%">
|
||||
<a style="color: #7dc7ff" href="{{ sort_links.name }}">{{ _('Contest') }}{{ sort_order.name }}</a>
|
||||
</th>
|
||||
<th>
|
||||
<a style="color: #7dc7ff" href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
|
||||
</th>
|
||||
{% if not request.in_contest %}
|
||||
<th style="width:15%"></th>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue