Change UI ranking

This commit is contained in:
cuom1999 2022-06-01 00:28:56 -05:00
parent d38342ad43
commit 9b1724cdad
16 changed files with 291 additions and 631 deletions

View file

@ -55,7 +55,7 @@ class DefaultContestFormat(BaseContestFormat):
format_data = (participation.format_data or {}).get(str(contest_problem.id))
if format_data:
return format_html(
'<td class="{state} problem-score-col"><a href="{url}">{points}<div class="solving-time">{time}</div></a></td>',
'<td class="{state} problem-score-col"><a data-featherlight="{url}" href="#">{points}<div class="solving-time">{time}</div></a></td>',
state=(
(
"pretest-"
@ -68,7 +68,7 @@ class DefaultContestFormat(BaseContestFormat):
)
),
url=reverse(
"contest_user_submissions",
"contest_user_submissions_ajax",
args=[
self.contest.key,
participation.user.user.username,

View file

@ -171,7 +171,8 @@ msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\\n"
""")
"""
)
if self.verbosity > 1:
self.stdout.write("processing navigation bar")
for label in NavigationBar.objects.values_list("label", flat=True):

View file

@ -561,29 +561,6 @@ class Problem(models.Model):
save.alters_data = True
def can_vote(self, request):
return False
user = request.user
if not user.is_authenticated:
return False
# If the user is in contest, nothing should be shown.
if request.in_contest_mode:
return False
# If the user is not allowed to vote
if user.profile.is_unlisted or user.profile.is_banned_problem_voting:
return False
# If the user is banned from submitting to the problem.
if self.banned_users.filter(pk=user.pk).exists():
return False
# If the user has a full AC submission to the problem (solved the problem).
return self.submission_set.filter(
user=user.profile, result="AC", points=F("problem__points")
).exists()
class Meta:
permissions = (
("see_private_problem", "See hidden problems"),

View file

@ -644,6 +644,7 @@ class KickUserWidgetView(
LoginRequiredMixin, AdminOrganizationMixin, SingleObjectMixin, View
):
model = Organization
def post(self, request, *args, **kwargs):
organization = self.get_object()
try:

View file

@ -306,78 +306,9 @@ class ProblemDetail(ProblemMixin, SolvedProblemMixin, CommentedDetailView):
context["meta_description"] = self.object.summary or metadata[0]
context["og_image"] = self.object.og_image or metadata[1]
context["can_vote"] = self.object.can_vote(self.request)
if context["can_vote"]:
try:
context["vote"] = ProblemPointsVote.objects.get(
voter=user.profile, problem=self.object
)
except ObjectDoesNotExist:
context["vote"] = None
else:
context["vote"] = None
context["has_votes"] = False
if user.is_superuser:
all_votes = list(
self.object.problem_points_votes.order_by("points").values_list(
"points", flat=True
)
)
context["all_votes"] = all_votes
context["has_votes"] = len(all_votes) > 0
context["max_possible_vote"] = 600
context["min_possible_vote"] = 100
return context
class DeleteVote(ProblemMixin, SingleObjectMixin, View):
def get(self, request, *args, **kwargs):
return HttpResponseForbidden(status=405, content_type="text/plain")
def post(self, request, *args, **kwargs):
self.object = self.get_object()
if not request.user.is_authenticated:
return HttpResponseForbidden("Not signed in.", content_type="text/plain")
elif self.object.can_vote(request.user):
ProblemPointsVote.objects.filter(
voter=request.profile, problem=self.object
).delete()
return HttpResponse("success", content_type="text/plain")
else:
return HttpResponseForbidden(
"Not allowed to delete votes on this problem.",
content_type="text/plain",
)
class Vote(ProblemMixin, SingleObjectMixin, View):
def get(self, request, *args, **kwargs):
return HttpResponseForbidden(status=405, content_type="text/plain")
def post(self, request, *args, **kwargs):
self.object = self.get_object()
if not self.object.can_vote(request): # Not allowed to vote for some reason.
return HttpResponseForbidden(
"Not allowed to vote on this problem.", content_type="text/plain"
)
form = ProblemPointsVoteForm(request.POST)
if form.is_valid():
with transaction.atomic():
# Delete any pre existing votes.
ProblemPointsVote.objects.filter(
voter=request.profile, problem=self.object
).delete()
vote = form.save(commit=False)
vote.voter = request.profile
vote.problem = self.object
vote.save()
return JsonResponse({"points": vote.points})
else:
return JsonResponse(form.errors, status=400)
class LatexError(Exception):
pass

View file

@ -18,6 +18,7 @@ from django.http import HttpResponseRedirect
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from django.template.defaultfilters import floatformat
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
@ -47,6 +48,7 @@ from judge.utils.problem_data import get_problem_case
from judge.utils.raw_sql import join_sql_subquery, use_straight_join
from judge.utils.views import DiggPaginatorMixin
from judge.utils.views import TitleMixin
from judge.utils.timedelta import nice_repr
def submission_related(queryset):
@ -358,7 +360,8 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
)
if self.selected_statuses:
queryset = queryset.filter(
Q(result__in=self.selected_statuses) | Q(status__in=self.selected_statuses)
Q(result__in=self.selected_statuses)
| Q(status__in=self.selected_statuses)
)
return queryset
@ -392,9 +395,7 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
hidden_codes = ["SC", "D", "G"]
if not self.request.user.is_superuser and not self.request.user.is_staff:
hidden_codes += ["IE"]
return [
(key, value) for key, value in all_statuses if key not in hidden_codes
]
return [(key, value) for key, value in all_statuses if key not in hidden_codes]
def get_context_data(self, **kwargs):
context = super(SubmissionsListBase, self).get_context_data(**kwargs)
@ -782,3 +783,30 @@ class UserContestSubmissions(ForceContestMixin, UserProblemSubmissions):
self.contest.name,
reverse("contest_view", args=[self.contest.key]),
)
class UserContestSubmissionsAjax(UserContestSubmissions):
template_name = "submission/user-ajax.html"
def contest_time(self, s):
if s.contest.participation.live:
return s.date - s.contest.participation.real_start
return None
def get_context_data(self, **kwargs):
context = super(UserContestSubmissionsAjax, self).get_context_data(**kwargs)
context["contest"] = self.contest
context["problem"] = self.problem
context["profile"] = self.profile
contest_problem = self.contest.contest_problems.get(problem=self.problem)
for s in context["submissions"]:
contest_time = self.contest_time(s)
if contest_time:
s.contest_time = nice_repr(contest_time, "noday")
else:
s.contest_time = None
points = floatformat(s.contest.points, -self.contest.points_precision)
total = floatformat(contest_problem.points, -self.contest.points_precision)
s.display_point = f"{points} / {total}"
return context