Add filter problems by solved
This commit is contained in:
parent
d1e5aaa3e1
commit
aa8abdec20
3 changed files with 23 additions and 4 deletions
|
@ -604,6 +604,9 @@ 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["have_editorial"] = 0 if self.in_contest else int(self.have_editorial)
|
context["have_editorial"] = 0 if self.in_contest else int(self.have_editorial)
|
||||||
|
context["show_solved_only"] = (
|
||||||
|
0 if self.in_contest else int(self.show_solved_only)
|
||||||
|
)
|
||||||
|
|
||||||
if self.request.profile:
|
if self.request.profile:
|
||||||
context["organizations"] = self.request.profile.organizations.all()
|
context["organizations"] = self.request.profile.organizations.all()
|
||||||
|
@ -704,6 +707,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
self.full_text = self.GET_with_session(request, "full_text")
|
self.full_text = self.GET_with_session(request, "full_text")
|
||||||
self.show_editorial = self.GET_with_session(request, "show_editorial")
|
self.show_editorial = self.GET_with_session(request, "show_editorial")
|
||||||
self.have_editorial = self.GET_with_session(request, "have_editorial")
|
self.have_editorial = self.GET_with_session(request, "have_editorial")
|
||||||
|
self.show_solved_only = self.GET_with_session(request, "show_solved_only")
|
||||||
|
|
||||||
self.search_query = None
|
self.search_query = None
|
||||||
self.category = None
|
self.category = None
|
||||||
|
@ -751,6 +755,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
"full_text",
|
"full_text",
|
||||||
"show_editorial",
|
"show_editorial",
|
||||||
"have_editorial",
|
"have_editorial",
|
||||||
|
"show_solved_only",
|
||||||
)
|
)
|
||||||
for key in to_update:
|
for key in to_update:
|
||||||
if key in request.GET:
|
if key in request.GET:
|
||||||
|
@ -810,6 +815,9 @@ class ProblemFeed(ProblemList):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
if self.feed_type == "volunteer":
|
||||||
|
self.hide_solved = 0
|
||||||
|
self.show_types = 1
|
||||||
queryset = super(ProblemFeed, self).get_queryset()
|
queryset = super(ProblemFeed, self).get_queryset()
|
||||||
|
|
||||||
if self.have_editorial:
|
if self.have_editorial:
|
||||||
|
@ -823,6 +831,12 @@ class ProblemFeed(ProblemList):
|
||||||
voted_problems = user.volunteer_problem_votes.values_list(
|
voted_problems = user.volunteer_problem_votes.values_list(
|
||||||
"problem", flat=True
|
"problem", flat=True
|
||||||
)
|
)
|
||||||
|
if self.show_solved_only:
|
||||||
|
queryset = queryset.filter(
|
||||||
|
id__in=Submission.objects.filter(
|
||||||
|
user=self.profile, points=F("problem__points")
|
||||||
|
).values_list("problem__id", flat=True)
|
||||||
|
)
|
||||||
return queryset.exclude(id__in=voted_problems).order_by("?")
|
return queryset.exclude(id__in=voted_problems).order_by("?")
|
||||||
if not settings.ML_OUTPUT_PATH or not user:
|
if not settings.ML_OUTPUT_PATH or not user:
|
||||||
return queryset.order_by("?")
|
return queryset.order_by("?")
|
||||||
|
@ -886,8 +900,6 @@ class ProblemFeed(ProblemList):
|
||||||
context["has_show_editorial_option"] = False
|
context["has_show_editorial_option"] = False
|
||||||
context["has_have_editorial_option"] = False
|
context["has_have_editorial_option"] = False
|
||||||
|
|
||||||
if self.feed_type == "volunteer":
|
|
||||||
context["problem_types"] = ProblemType.objects.all()
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
|
|
||||||
$('#go').click(clean_submit);
|
$('#go').click(clean_submit);
|
||||||
|
|
||||||
$('input#full_text, input#hide_solved, input#show_types, input#show_editorial, input#have_editorial').click(function () {
|
$('input#full_text, input#hide_solved, input#show_types, input#show_editorial, input#have_editorial, input#show_solved_only').click(function () {
|
||||||
prep_form();
|
prep_form();
|
||||||
($('<form>').attr('action', window.location.pathname + '?' + form_serialize())
|
($('<form>').attr('action', window.location.pathname + '?' + form_serialize())
|
||||||
.append($('<input>').attr('type', 'hidden').attr('name', 'csrfmiddlewaretoken')
|
.append($('<input>').attr('type', 'hidden').attr('name', 'csrfmiddlewaretoken')
|
||||||
|
|
|
@ -7,13 +7,20 @@
|
||||||
<input id="search" type="text" name="search" value="{{ search_query or '' }}"
|
<input id="search" type="text" name="search" value="{{ search_query or '' }}"
|
||||||
placeholder="{{ _('Search problems...') }}">
|
placeholder="{{ _('Search problems...') }}">
|
||||||
</div>
|
</div>
|
||||||
{% if request.user.is_authenticated %}
|
{% if feed_type != 'volunteer' and request.user.is_authenticated %}
|
||||||
<div>
|
<div>
|
||||||
<input id="hide_solved" type="checkbox" name="hide_solved" value="1"
|
<input id="hide_solved" type="checkbox" name="hide_solved" value="1"
|
||||||
{% if hide_solved %}checked{% endif %}>
|
{% if hide_solved %}checked{% endif %}>
|
||||||
<label for="hide_solved">{{ _('Hide solved problems') }}</label>
|
<label for="hide_solved">{{ _('Hide solved problems') }}</label>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if feed_type == 'volunteer' and request.user.is_authenticated %}
|
||||||
|
<div>
|
||||||
|
<input id="show_solved_only" type="checkbox" name="show_solved_only" value="1"
|
||||||
|
{% if show_solved_only %}checked{% endif %}>
|
||||||
|
<label for="show_solved_only">{{ _('Show solved problems') }}</label>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if feed_type != 'volunteer' %}
|
{% if feed_type != 'volunteer' %}
|
||||||
<div>
|
<div>
|
||||||
<input id="show_types" type="checkbox" name="show_types" value="1"
|
<input id="show_types" type="checkbox" name="show_types" value="1"
|
||||||
|
|
Loading…
Reference in a new issue