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.models import ContestProblem, ContestSubmission, Judge, Language, Problem, ProblemGroup, \
|
||||
ProblemTranslation, ProblemType, RuntimeVersion, Solution, Submission, SubmissionSource, \
|
||||
TranslatedProblemForeignKeyQuerySet
|
||||
TranslatedProblemForeignKeyQuerySet, Organization
|
||||
from judge.pdf_problems import DefaultPdfMaker, HAS_PDF
|
||||
from judge.utils.diggpaginator import DiggPaginator
|
||||
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:
|
||||
queryset = queryset.exclude(id__in=Submission.objects.filter(user=self.profile, points=F('problem__points'))
|
||||
.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:
|
||||
queryset = queryset.prefetch_related('types')
|
||||
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['show_editorial'] = 0 if self.in_contest else int(self.show_editorial)
|
||||
|
||||
context['organizations'] = Organization.objects.all()
|
||||
context['category'] = self.category
|
||||
context['categories'] = ProblemGroup.objects.all()
|
||||
if self.show_types:
|
||||
context['selected_types'] = self.selected_types
|
||||
context['problem_types'] = ProblemType.objects.all()
|
||||
context['has_fts'] = settings.ENABLE_FTS
|
||||
context['org_query'] = self.org_query
|
||||
context['search_query'] = self.search_query
|
||||
context['completed_problem_ids'] = self.get_completed_problems()
|
||||
context['attempted_problems'] = self.get_attempted_problems()
|
||||
|
@ -467,6 +473,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
|
||||
self.search_query = None
|
||||
self.category = None
|
||||
self.org_query = []
|
||||
self.selected_types = []
|
||||
|
||||
# This actually copies into the instance dictionary...
|
||||
|
@ -481,6 +488,12 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
except ValueError:
|
||||
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_end = safe_float_or_none(request.GET.get('point_end'))
|
||||
|
||||
|
|
|
@ -3,13 +3,17 @@
|
|||
{% block media %}
|
||||
<link rel="stylesheet" href="{{ static('libs/nouislider.min.css') }}">
|
||||
<noscript>
|
||||
<style>#category, #types {
|
||||
visibility: visible;
|
||||
}
|
||||
<style>
|
||||
#category, #types {
|
||||
visibility: visible;
|
||||
}
|
||||
</style>
|
||||
</noscript>
|
||||
{% if not request.in_contest %}
|
||||
<style>
|
||||
#search-org {
|
||||
width: 100%;
|
||||
}
|
||||
#problem-table th {
|
||||
padding: 0;
|
||||
}
|
||||
|
@ -61,6 +65,8 @@
|
|||
$category.select2().css({'visibility': 'visible'}).change(clean_submit);
|
||||
$('#types').select2({multiple: 1, placeholder: '{{ _('Filter by type...') }}'})
|
||||
.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
|
||||
$search.keypress(function (e) {
|
||||
|
|
|
@ -31,6 +31,16 @@
|
|||
{% if show_editorial %} checked{% endif %}>
|
||||
<label for="show_editorial">{{ _('Show editorial') }}</label>
|
||||
</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">
|
||||
<label for="category"><i>{{ _('Category') }}</i></label>
|
||||
<select id="category" name="category">
|
||||
|
@ -45,6 +55,7 @@
|
|||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
</div>
|
||||
{% if show_types %}
|
||||
<div class="filter-form-group">
|
||||
|
|
Loading…
Reference in a new issue