Add contest search

This commit is contained in:
cuom1999 2021-02-19 02:02:12 -06:00
parent f7fd4cae50
commit 628a3680d4
2 changed files with 84 additions and 2 deletions

View file

@ -31,7 +31,7 @@ from judge import event_poster as event
from judge.comments import CommentedDetailView from judge.comments import CommentedDetailView
from judge.forms import ContestCloneForm from judge.forms import ContestCloneForm
from judge.models import Contest, ContestMoss, ContestParticipation, ContestProblem, ContestTag, \ from judge.models import Contest, ContestMoss, ContestParticipation, ContestProblem, ContestTag, \
Problem, Profile, Submission Organization, Problem, Profile, Submission
from judge.tasks import run_moss from judge.tasks import run_moss
from judge.utils.celery import redirect_to_task_status from judge.utils.celery import redirect_to_task_status
from judge.utils.opengraph import generate_opengraph from judge.utils.opengraph import generate_opengraph
@ -86,9 +86,31 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
def _now(self): def _now(self):
return timezone.now() return timezone.now()
def get(self, request, *args, **kwargs):
self.contest_query = None
self.org_query = []
if 'orgs' in self.request.GET:
try:
self.org_query = list(map(int, request.GET.getlist('orgs')))
except ValueError:
pass
return super(ContestList, self).get(request, *args, **kwargs)
def _get_queryset(self): def _get_queryset(self):
return super(ContestList, self).get_queryset() \ queryset = super(ContestList, self).get_queryset() \
.order_by('-start_time', 'key').prefetch_related('tags', 'organizations', 'organizers') .order_by('-start_time', 'key').prefetch_related('tags', 'organizations', 'organizers')
if 'contest' in self.request.GET:
self.contest_query = query = ' '.join(self.request.GET.getlist('contest')).strip()
if query:
queryset = queryset.filter(
Q(key__icontains=query) | Q(name__icontains=query))
if self.org_query:
queryset = queryset.filter(organizations__in=self.org_query)
return queryset
def get_queryset(self): def get_queryset(self):
return self._get_queryset().filter(end_time__lt=self._now) return self._get_queryset().filter(end_time__lt=self._now)
@ -117,6 +139,9 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView):
context['future_contests'] = future context['future_contests'] = future
context['now'] = self._now context['now'] = self._now
context['first_page_href'] = '.' context['first_page_href'] = '.'
context['contest_query'] = self.contest_query
context['org_query'] = self.org_query
context['organizations'] = Organization.objects.all()
return context return context

View file

@ -26,6 +26,46 @@
} }
{% endif %} {% endif %}
@media (max-width: 500px) {
#search-contest, #search-org, #search-btn {
width: 100%;
margin-bottom: 0.5em;
}
#search-contest {
height: 2.5em;
}
#search-btn {
margin-top: 0.5em;
}
#filter-form input {
padding-left: 8px;
}
}
@media (min-width: 500px) {
#filter-form input {
margin: 0 0.5em 0 0!important;
padding-left: 8px;
padding-top: 8px;
}
#search-contest {
width: 30%;
height: 2.3em;
margin-right: 1em;
margin-bottom: 0;
padding-top: 4px !important;
}
#search-org {
width: 40%;
}
#search-btn {
display: inline-block;
height: 2.3em;
margin-left: 0.5em;
}
}
</style> </style>
{% endblock %} {% endblock %}
@ -59,6 +99,9 @@
makeToggleBtn($("#ongoing-btn"), $("#ongoing-table")); makeToggleBtn($("#ongoing-btn"), $("#ongoing-table"));
$('#search-org').select2({multiple: 1, placeholder: '{{ _('Organizations...') }}'})
.css({'visibility': 'visible'});
// var tooltip_classes = 'tooltipped tooltipped-e'; // var tooltip_classes = 'tooltipped tooltipped-e';
// //
// $('.contest-tag').each(function () { // $('.contest-tag').each(function () {
@ -171,6 +214,20 @@
{% block body %} {% block body %}
<div class="content-description"> <div class="content-description">
<form id="filter-form">
<input id="search-contest" type="text" name="contest" value="{{ contest_query or '' }}"
placeholder="{{ _('Search contests...') }}">
<select id="search-org" name="orgs" multiple>
{% for org in organizations %}
<option value="{{ org.id }}"{% if org.id in org_query %} selected{% endif %}>
{{ org.name }}
</option>
{% endfor %}
</select>
<button id="search-btn"> {{ _('Search')}} </button>
</form>
{% if active_participations %} {% if active_participations %}
<h4>{{ _('Active Contests') }}</h4> <h4>{{ _('Active Contests') }}</h4>
<table class="contest-list table striped"> <table class="contest-list table striped">