add vote mean and std to problem admin
This commit is contained in:
parent
ce77242008
commit
30a856dcb9
3 changed files with 17 additions and 3 deletions
|
@ -3,7 +3,8 @@ from operator import attrgetter
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q, Avg
|
||||||
|
from django.db.models.aggregates import StdDev
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
@ -131,7 +132,7 @@ class ProblemAdmin(VersionAdmin):
|
||||||
(_('Justice'), {'fields': ('banned_users',)}),
|
(_('Justice'), {'fields': ('banned_users',)}),
|
||||||
(_('History'), {'fields': ('change_message',)}),
|
(_('History'), {'fields': ('change_message',)}),
|
||||||
)
|
)
|
||||||
list_display = ['code', 'name', 'show_authors', 'points', 'is_public', 'show_public']
|
list_display = ['code', 'name', 'show_authors', 'points', 'vote_mean', 'vote_std', 'is_public', 'show_public']
|
||||||
ordering = ['code']
|
ordering = ['code']
|
||||||
search_fields = ('code', 'name', 'authors__user__username', 'curators__user__username')
|
search_fields = ('code', 'name', 'authors__user__username', 'curators__user__username')
|
||||||
inlines = [LanguageLimitInline, ProblemClarificationInline, ProblemSolutionInline, ProblemTranslationInline]
|
inlines = [LanguageLimitInline, ProblemClarificationInline, ProblemSolutionInline, ProblemTranslationInline]
|
||||||
|
@ -198,6 +199,10 @@ class ProblemAdmin(VersionAdmin):
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
queryset = Problem.objects.prefetch_related('authors__user')
|
queryset = Problem.objects.prefetch_related('authors__user')
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
_vote_mean=Avg('problem_points_votes__points'),
|
||||||
|
_vote_std=StdDev('problem_points_votes__points')
|
||||||
|
)
|
||||||
if request.user.has_perm('judge.edit_all_problem'):
|
if request.user.has_perm('judge.edit_all_problem'):
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -237,6 +242,14 @@ class ProblemAdmin(VersionAdmin):
|
||||||
return form.cleaned_data['change_message']
|
return form.cleaned_data['change_message']
|
||||||
return super(ProblemAdmin, self).construct_change_message(request, form, *args, **kwargs)
|
return super(ProblemAdmin, self).construct_change_message(request, form, *args, **kwargs)
|
||||||
|
|
||||||
|
def vote_mean(self, obj):
|
||||||
|
return round(obj._vote_mean, 1) if obj._vote_mean is not None else None
|
||||||
|
vote_mean.admin_order_field = '_vote_mean'
|
||||||
|
|
||||||
|
def vote_std(self, obj):
|
||||||
|
return round(obj._vote_std, 1) if obj._vote_std is not None else None
|
||||||
|
vote_std.admin_order_field = '_vote_std'
|
||||||
|
|
||||||
|
|
||||||
class ProblemPointsVoteAdmin(admin.ModelAdmin):
|
class ProblemPointsVoteAdmin(admin.ModelAdmin):
|
||||||
list_display = ('vote_points', 'voter', 'voter_rating', 'voter_point', 'problem_name', 'problem_code', 'problem_points')
|
list_display = ('vote_points', 'voter', 'voter_rating', 'voter_point', 'problem_name', 'problem_code', 'problem_points')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
from math import sqrt
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
|
|
@ -749,7 +749,7 @@ msgstr "giới hạn thời gian"
|
||||||
|
|
||||||
#: judge/models/contest.py:76 judge/models/problem.py:136
|
#: judge/models/contest.py:76 judge/models/problem.py:136
|
||||||
msgid "publicly visible"
|
msgid "publicly visible"
|
||||||
msgstr "hiển thị công khai"
|
msgstr "công khai"
|
||||||
|
|
||||||
#: judge/models/contest.py:77
|
#: judge/models/contest.py:77
|
||||||
msgid ""
|
msgid ""
|
||||||
|
|
Loading…
Reference in a new issue