diff --git a/judge/views/contests.py b/judge/views/contests.py index ba88d74..e95f1f4 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -31,7 +31,7 @@ from judge import event_poster as event from judge.comments import CommentedDetailView from judge.forms import ContestCloneForm from judge.models import Contest, ContestMoss, ContestParticipation, ContestProblem, ContestTag, \ - Problem, Profile, Submission + Organization, Problem, Profile, Submission from judge.tasks import run_moss from judge.utils.celery import redirect_to_task_status from judge.utils.opengraph import generate_opengraph @@ -86,9 +86,31 @@ class ContestList(DiggPaginatorMixin, TitleMixin, ContestListMixin, ListView): def _now(self): 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): - return super(ContestList, self).get_queryset() \ + queryset = super(ContestList, self).get_queryset() \ .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): 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['now'] = self._now context['first_page_href'] = '.' + context['contest_query'] = self.contest_query + context['org_query'] = self.org_query + context['organizations'] = Organization.objects.all() return context diff --git a/templates/contest/list.html b/templates/contest/list.html index 791cb54..f10b067 100644 --- a/templates/contest/list.html +++ b/templates/contest/list.html @@ -26,6 +26,46 @@ } {% 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; + } + } {% endblock %} @@ -59,6 +99,9 @@ makeToggleBtn($("#ongoing-btn"), $("#ongoing-table")); + $('#search-org').select2({multiple: 1, placeholder: '{{ _('Organizations...') }}'}) + .css({'visibility': 'visible'}); + // var tooltip_classes = 'tooltipped tooltipped-e'; // // $('.contest-tag').each(function () { @@ -171,6 +214,20 @@ {% block body %}
+ +
+ + + + +
{% if active_participations %}

{{ _('Active Contests') }}