Make internal problem faster
This commit is contained in:
parent
e5b2481345
commit
87d7484a89
3 changed files with 60 additions and 36 deletions
|
@ -6,6 +6,7 @@ from django.utils.translation import gettext as _, gettext_lazy
|
|||
from django.db.models import Count, Q
|
||||
from django.http import HttpResponseForbidden
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import render
|
||||
|
||||
from judge.utils.diggpaginator import DiggPaginator
|
||||
from judge.models import VolunteerProblemVote, Problem
|
||||
|
@ -21,7 +22,7 @@ class InternalView(object):
|
|||
class InternalProblem(InternalView, ListView):
|
||||
model = Problem
|
||||
title = _("Internal problems")
|
||||
template_name = "internal/problem.html"
|
||||
template_name = "internal/problem/problem.html"
|
||||
paginate_by = 100
|
||||
context_object_name = "problems"
|
||||
|
||||
|
@ -63,6 +64,28 @@ class InternalProblem(InternalView, ListView):
|
|||
return context
|
||||
|
||||
|
||||
def get_problem_votes(request):
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseForbidden()
|
||||
try:
|
||||
problem = Problem.objects.get(id=request.GET.get("id"))
|
||||
except:
|
||||
return HttpResponseForbidden()
|
||||
votes = (
|
||||
problem.volunteer_user_votes.select_related("voter")
|
||||
.prefetch_related("types")
|
||||
.order_by("id")
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"internal/problem/votes.html",
|
||||
{
|
||||
"problem": problem,
|
||||
"votes": votes,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class RequestTimeMixin(object):
|
||||
def get_requests_data(self):
|
||||
logger = logging.getLogger(self.log_name)
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
$('.vote-detail').each(function() {
|
||||
$(this).on('click', function() {
|
||||
var pid = $(this).attr('pid');
|
||||
$('.detail').hide();
|
||||
$('#detail-'+pid).show();
|
||||
$.get("{{url('internal_problem_votes')}}?id="+pid, function(data) {
|
||||
$('#detail').html(data);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
|
@ -59,37 +60,8 @@
|
|||
|
||||
{% block right_sidebar %}
|
||||
<div style="display: block; width: 100%">
|
||||
<div><a href="{{url('admin:judge_volunteerproblemvote_changelist')}}">{{_('Admin')}}</a></div>
|
||||
{% for problem in problems %}
|
||||
<div class="detail" id="detail-{{problem.id}}" style="display: none;">
|
||||
<h3>{{_('Votes for problem') }} {{problem.name}}</h3>
|
||||
<ol>
|
||||
{% for vote in problem.volunteer_user_votes.order_by('id') %}
|
||||
<li>
|
||||
<h4> {{link_user(vote.voter)}} </h4>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width:10%">{{_('Knowledge')}}</td>
|
||||
<td>{{vote.knowledge_points}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Thinking')}}</td>
|
||||
<td>{{vote.thinking_points}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Types')}}</td>
|
||||
<td>{{vote.types.all() | join(', ')}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Feedback')}}</td>
|
||||
<td>{{vote.feedback}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
<a href="{{url('admin:judge_volunteerproblemvote_changelist')}}">{{_('Admin')}}</a>
|
||||
<div class="detail" id="detail">
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
29
templates/internal/problem/votes.html
Normal file
29
templates/internal/problem/votes.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
<h3>{{_('Votes for problem') }} {{problem.name}}</h3>
|
||||
<ol>
|
||||
{% for vote in votes %}
|
||||
<li>
|
||||
<h4> {{link_user(vote.voter)}} </h4>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width:10%">{{_('Knowledge')}}</td>
|
||||
<td>{{vote.knowledge_points}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Thinking')}}</td>
|
||||
<td>{{vote.thinking_points}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Types')}}</td>
|
||||
<td>{{vote.types.all() | join(', ')}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{_('Feedback')}}</td>
|
||||
<td>{{vote.feedback}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</div>
|
Loading…
Reference in a new issue