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.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||||
from django.db import transaction
|
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.db.utils import ProgrammingError
|
||||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
|
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, render
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(ProblemList, self).get_context_data(**kwargs)
|
context = super(ProblemList, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
context['hide_solved'] = 0 if self.in_contest else int(self.hide_solved)
|
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['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['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['category'] = self.category
|
||||||
context['categories'] = ProblemGroup.objects.all()
|
context['categories'] = ProblemGroup.objects.all()
|
||||||
if self.show_types:
|
if self.show_types:
|
||||||
|
@ -456,7 +464,8 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
self.hide_solved = self.GET_with_session(request, 'hide_solved')
|
self.hide_solved = self.GET_with_session(request, 'hide_solved')
|
||||||
self.show_types = self.GET_with_session(request, 'show_types')
|
self.show_types = self.GET_with_session(request, 'show_types')
|
||||||
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.search_query = None
|
self.search_query = None
|
||||||
self.category = None
|
self.category = None
|
||||||
self.selected_types = []
|
self.selected_types = []
|
||||||
|
@ -485,7 +494,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
|
||||||
return generic_message(request, 'FTS syntax error', e.args[1], status=400)
|
return generic_message(request, 'FTS syntax error', e.args[1], status=400)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
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:
|
for key in to_update:
|
||||||
if key in request.GET:
|
if key in request.GET:
|
||||||
val = request.GET.get(key) == '1'
|
val = request.GET.get(key) == '1'
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
|
|
||||||
$('#go').click(clean_submit);
|
$('#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();
|
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')
|
||||||
|
@ -245,11 +245,16 @@
|
||||||
<th class="users">
|
<th class="users">
|
||||||
<a href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
|
<a href="{{ sort_links.user_count }}">{{ _('Users') }}{{ sort_order.user_count }}</a>
|
||||||
</th>
|
</th>
|
||||||
|
{% if show_editorial %}
|
||||||
|
<th class="editorial">
|
||||||
|
Editorial
|
||||||
|
</th>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for problem in problems %}
|
{% for problem in object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
{% if problem.id in completed_problem_ids %}
|
{% if problem.id in completed_problem_ids %}
|
||||||
|
@ -311,6 +316,13 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
{% if show_types %} checked{% endif %}>
|
{% if show_types %} checked{% endif %}>
|
||||||
<label for="show_types">{{ _('Show problem types') }}</label>
|
<label for="show_types">{{ _('Show problem types') }}</label>
|
||||||
</div>
|
</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">
|
<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">
|
||||||
|
|
Loading…
Reference in a new issue