Add organization to problem search
This commit is contained in:
parent
5a892f5a17
commit
ffb6797c64
3 changed files with 34 additions and 4 deletions
|
@ -29,7 +29,7 @@ from judge.comments import CommentedDetailView
|
||||||
from judge.forms import ProblemCloneForm, ProblemSubmitForm
|
from judge.forms import ProblemCloneForm, ProblemSubmitForm
|
||||||
from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
|
from judge.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
|
||||||
ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \
|
ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \
|
||||||
TranslatedProblemForeignKeyQuerySet
|
TranslatedProblemForeignKeyQuerySet, Organization
|
||||||
from judge.pdf_problems import DefaultPdfMaker, HAS_PDF
|
from judge.pdf_problems import DefaultPdfMaker, HAS_PDF
|
||||||
from judge.utils.diggpaginator import DiggPaginator
|
from judge.utils.diggpaginator import DiggPaginator
|
||||||
from judge.utils.opengraph import generate_opengraph
|
from judge.utils.opengraph import generate_opengraph
|
||||||
|
@ -374,6 +374,10 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
if self.profile is not None and self.hide_solved:
|
if self.profile is not None and self.hide_solved:
|
||||||
queryset = queryset.exclude(id__in=Submission.objects.filter(user=self.profile, points=F('problem__points'))
|
queryset = queryset.exclude(id__in=Submission.objects.filter(user=self.profile, points=F('problem__points'))
|
||||||
.values_list('problem__id', flat=True))
|
.values_list('problem__id', flat=True))
|
||||||
|
if self.org_query:
|
||||||
|
queryset = queryset.filter(
|
||||||
|
Q(organizations__in=self.org_query) |
|
||||||
|
Q(contests__contest__organizations__in=self.org_query))
|
||||||
if self.show_types:
|
if self.show_types:
|
||||||
queryset = queryset.prefetch_related('types')
|
queryset = queryset.prefetch_related('types')
|
||||||
if self.category is not None:
|
if self.category is not None:
|
||||||
|
@ -414,12 +418,14 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
context['full_text'] = 0 if self.in_contest else int(self.full_text)
|
context['full_text'] = 0 if self.in_contest else int(self.full_text)
|
||||||
context['show_editorial'] = 0 if self.in_contest else int(self.show_editorial)
|
context['show_editorial'] = 0 if self.in_contest else int(self.show_editorial)
|
||||||
|
|
||||||
|
context['organizations'] = Organization.objects.all()
|
||||||
context['category'] = self.category
|
context['category'] = self.category
|
||||||
context['categories'] = ProblemGroup.objects.all()
|
context['categories'] = ProblemGroup.objects.all()
|
||||||
if self.show_types:
|
if self.show_types:
|
||||||
context['selected_types'] = self.selected_types
|
context['selected_types'] = self.selected_types
|
||||||
context['problem_types'] = ProblemType.objects.all()
|
context['problem_types'] = ProblemType.objects.all()
|
||||||
context['has_fts'] = settings.ENABLE_FTS
|
context['has_fts'] = settings.ENABLE_FTS
|
||||||
|
context['org_query'] = self.org_query
|
||||||
context['search_query'] = self.search_query
|
context['search_query'] = self.search_query
|
||||||
context['completed_problem_ids'] = self.get_completed_problems()
|
context['completed_problem_ids'] = self.get_completed_problems()
|
||||||
context['attempted_problems'] = self.get_attempted_problems()
|
context['attempted_problems'] = self.get_attempted_problems()
|
||||||
|
@ -467,6 +473,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
|
|
||||||
self.search_query = None
|
self.search_query = None
|
||||||
self.category = None
|
self.category = None
|
||||||
|
self.org_query = []
|
||||||
self.selected_types = []
|
self.selected_types = []
|
||||||
|
|
||||||
# This actually copies into the instance dictionary...
|
# This actually copies into the instance dictionary...
|
||||||
|
@ -481,6 +488,12 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if 'orgs' in request.GET:
|
||||||
|
try:
|
||||||
|
self.org_query = list(map(int, request.GET.getlist('orgs')))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.point_start = safe_float_or_none(request.GET.get('point_start'))
|
self.point_start = safe_float_or_none(request.GET.get('point_start'))
|
||||||
self.point_end = safe_float_or_none(request.GET.get('point_end'))
|
self.point_end = safe_float_or_none(request.GET.get('point_end'))
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,17 @@
|
||||||
{% block media %}
|
{% block media %}
|
||||||
<link rel="stylesheet" href="{{ static('libs/nouislider.min.css') }}">
|
<link rel="stylesheet" href="{{ static('libs/nouislider.min.css') }}">
|
||||||
<noscript>
|
<noscript>
|
||||||
<style>#category, #types {
|
<style>
|
||||||
visibility: visible;
|
#category, #types {
|
||||||
}
|
visibility: visible;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</noscript>
|
</noscript>
|
||||||
{% if not request.in_contest %}
|
{% if not request.in_contest %}
|
||||||
<style>
|
<style>
|
||||||
|
#search-org {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
#problem-table th {
|
#problem-table th {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +65,8 @@
|
||||||
$category.select2().css({'visibility': 'visible'}).change(clean_submit);
|
$category.select2().css({'visibility': 'visible'}).change(clean_submit);
|
||||||
$('#types').select2({multiple: 1, placeholder: '{{ _('Filter by type...') }}'})
|
$('#types').select2({multiple: 1, placeholder: '{{ _('Filter by type...') }}'})
|
||||||
.css({'visibility': 'visible'});
|
.css({'visibility': 'visible'});
|
||||||
|
$('#search-org').select2({multiple: 1, placeholder: '{{ _('Organizations...') }}'})
|
||||||
|
.css({'visibility': 'visible'});
|
||||||
|
|
||||||
// This is incredibly nasty to do but it's needed because otherwise the select2 steals the focus
|
// This is incredibly nasty to do but it's needed because otherwise the select2 steals the focus
|
||||||
$search.keypress(function (e) {
|
$search.keypress(function (e) {
|
||||||
|
|
|
@ -31,6 +31,16 @@
|
||||||
{% if show_editorial %} checked{% endif %}>
|
{% if show_editorial %} checked{% endif %}>
|
||||||
<label for="show_editorial">{{ _('Show editorial') }}</label>
|
<label for="show_editorial">{{ _('Show editorial') }}</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="filter-form-group">
|
||||||
|
<label for="type"><i>{{ _('Organization') }}</i></label>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
<div class="filter-form-group">
|
<div class="filter-form-group">
|
||||||
<label for="category"><i>{{ _('Category') }}</i></label>
|
<label for="category"><i>{{ _('Category') }}</i></label>
|
||||||
<select id="category" name="category">
|
<select id="category" name="category">
|
||||||
|
@ -45,6 +55,7 @@
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% if show_types %}
|
{% if show_types %}
|
||||||
<div class="filter-form-group">
|
<div class="filter-form-group">
|
||||||
|
|
Loading…
Reference in a new issue