add editorial column to problem table
This commit is contained in:
parent
e00a64e49b
commit
3876896b97
3 changed files with 31 additions and 5 deletions
|
@ -10,7 +10,7 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, F, Prefetch, Q
|
||||
from django.db.models import Count, F, Prefetch, Q, Sum, Case, When, IntegerField
|
||||
from django.db.utils import ProgrammingError
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
@ -404,9 +404,17 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ProblemList, self).get_context_data(**kwargs)
|
||||
|
||||
context['hide_solved'] = 0 if self.in_contest else int(self.hide_solved)
|
||||
context['show_types'] = 0 if self.in_contest else int(self.show_types)
|
||||
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)
|
||||
|
||||
if (context['show_editorial']):
|
||||
context['object_list'] = context['object_list'] \
|
||||
.annotate(has_public_editorial=Sum(Case(When(solution__is_public=True, then=1),
|
||||
default=0, output_field=IntegerField())))
|
||||
|
||||
context['category'] = self.category
|
||||
context['categories'] = ProblemGroup.objects.all()
|
||||
if self.show_types:
|
||||
|
@ -456,6 +464,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
self.hide_solved = self.GET_with_session(request, 'hide_solved')
|
||||
self.show_types = self.GET_with_session(request, 'show_types')
|
||||
self.full_text = self.GET_with_session(request, 'full_text')
|
||||
self.show_editorial = self.GET_with_session(request, 'show_editorial')
|
||||
|
||||
self.search_query = None
|
||||
self.category = None
|
||||
|
@ -485,7 +494,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
|||
return generic_message(request, 'FTS syntax error', e.args[1], status=400)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
to_update = ('hide_solved', 'show_types', 'full_text')
|
||||
to_update = ('hide_solved', 'show_types', 'full_text', 'show_editorial')
|
||||
for key in to_update:
|
||||
if key in request.GET:
|
||||
val = request.GET.get(key) == '1'
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
$('#go').click(clean_submit);
|
||||
|
||||
$('input#full_text, input#hide_solved, input#show_types').click(function () {
|
||||
$('input#full_text, input#hide_solved, input#show_types, input#show_editorial').click(function () {
|
||||
prep_form();
|
||||
($('<form>').attr('action', window.location.pathname + '?' + $form.serialize())
|
||||
.append($('<input>').attr('type', 'hidden').attr('name', 'csrfmiddlewaretoken')
|
||||
|
@ -245,11 +245,16 @@
|
|||
<th class="users">
|
||||
<a href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
|
||||
</th>
|
||||
{% if show_editorial %}
|
||||
<th class="editorial">
|
||||
Editorial
|
||||
</th>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for problem in problems %}
|
||||
{% for problem in object_list %}
|
||||
<tr>
|
||||
{% if request.user.is_authenticated %}
|
||||
{% if problem.id in completed_problem_ids %}
|
||||
|
@ -311,6 +316,13 @@
|
|||
{% endif %}
|
||||
</a>
|
||||
</td>
|
||||
{% if show_editorial%}
|
||||
<td class="editorial">
|
||||
{% if problem.has_public_editorial %}
|
||||
<a href="{{ url('problem_editorial', problem.code) }}">{{ _('Editorial') }}</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -26,6 +26,11 @@
|
|||
{% if show_types %} checked{% endif %}>
|
||||
<label for="show_types">{{ _('Show problem types') }}</label>
|
||||
</div>
|
||||
<div>
|
||||
<input id="show_editorial" type="checkbox" name="show_editorial" value="1"
|
||||
{% if show_editorial %} checked{% endif %}>
|
||||
<label for="show_editorial">{{ _('Show editorial') }}</label>
|
||||
</div>
|
||||
<div class="filter-form-group">
|
||||
<label for="category"><i>{{ _('Category') }}</i></label>
|
||||
<select id="category" name="category">
|
||||
|
|
Loading…
Reference in a new issue