From 87d7484a89a85c31e81c2eca310962568525383c Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 1 Nov 2023 21:17:54 -0500 Subject: [PATCH] Make internal problem faster --- judge/views/internal.py | 25 ++++++++++- templates/internal/{ => problem}/problem.html | 42 ++++--------------- templates/internal/problem/votes.html | 29 +++++++++++++ 3 files changed, 60 insertions(+), 36 deletions(-) rename templates/internal/{ => problem}/problem.html (53%) create mode 100644 templates/internal/problem/votes.html diff --git a/judge/views/internal.py b/judge/views/internal.py index eff02a4..060a2c3 100644 --- a/judge/views/internal.py +++ b/judge/views/internal.py @@ -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) diff --git a/templates/internal/problem.html b/templates/internal/problem/problem.html similarity index 53% rename from templates/internal/problem.html rename to templates/internal/problem/problem.html index d1147e8..0421362 100644 --- a/templates/internal/problem.html +++ b/templates/internal/problem/problem.html @@ -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 %}
-
{{_('Admin')}}
- {% for problem in problems %} - - {% endfor %} + {{_('Admin')}} +
+
+
{% endblock %} \ No newline at end of file diff --git a/templates/internal/problem/votes.html b/templates/internal/problem/votes.html new file mode 100644 index 0000000..74e4af8 --- /dev/null +++ b/templates/internal/problem/votes.html @@ -0,0 +1,29 @@ +

{{_('Votes for problem') }} {{problem.name}}

+
    + {% for vote in votes %} +
  1. +

    {{link_user(vote.voter)}}

    + + + + + + + + + + + + + + + + + + + +
    {{_('Knowledge')}}{{vote.knowledge_points}}
    {{_('Thinking')}}{{vote.thinking_points}}
    {{_('Types')}}{{vote.types.all() | join(', ')}}
    {{_('Feedback')}}{{vote.feedback}}
    +
  2. + {% endfor %} +
+