From a5a313d2fe7a8aaaa23bd218c609fa4c0408086e Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sun, 24 Apr 2016 14:32:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8E=92=E5=90=8D=E7=9A=84=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/management/commands/inituserrank.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils/management/commands/inituserrank.py diff --git a/utils/management/commands/inituserrank.py b/utils/management/commands/inituserrank.py new file mode 100644 index 00000000..cebe3a0e --- /dev/null +++ b/utils/management/commands/inituserrank.py @@ -0,0 +1,19 @@ +# coding=utf-8 +from django.core.management.base import BaseCommand +from account.models import UserProfile +from submission.models import Submission + + +class Command(BaseCommand): + def handle(self, *args, **options): + self.stdout.write(self.style.SUCCESS("Please wait a minute")) + for profile in UserProfile.objects.all(): + submissions = Submission.objects.filter(user_id=profile.user.id) + profile.submission_number = submissions.count() + accepted_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=True)\ + .values_list("problem_id", flat=True))) + accepted_contest_problem_number = len(set(Submission.objects.filter(user_id=profile.user.id, contest_id__isnull=False)\ + .values_list("problem_id", flat=True))) + profile.accepted_problem_number = accepted_problem_number + accepted_contest_problem_number + profile.save() + self.stdout.write(self.style.SUCCESS("Succeeded"))