def post(self, request, cid): contest_participant, _ = self.contest.contestparticipant_set.get_or_create(user=self.user) self.prepare_submissions() if len(self.submissions) > 0: for submission in self.submissions: submission.pk = None submission.contest = self.contest Submission.objects.bulk_create(self.submissions) invalidate_contest_participant(self.contest, self.user.pk) for problem in Problem.objects.filter(pk__in=self.problem_id_list): invalidate_problem(problem) messages.add_message(request, messages.SUCCESS, "%d 份提交已经成功迁移。" % len(self.submissions)) return HttpResponse()
def post(self, request, cid): contest_participant, _ = self.contest.contestparticipant_set.get_or_create( user=self.user) self.prepare_submissions() if len(self.submissions) > 0: for submission in self.submissions: submission.pk = None submission.contest = self.contest Submission.objects.bulk_create(self.submissions) invalidate_contest_participant(self.contest, self.user.pk) invalidate_problem(self.problem_id_list, self.contest.pk) messages.add_message( request, messages.SUCCESS, "%d submissions successfully migrated." % len(self.submissions)) return HttpResponse()
def run(self): try: with transaction.atomic(): for submission in Submission.objects.filter( author=self.old_user).order_by("create_time").all(): if submission.contest_id: # Clone one s = Submission.objects.create( lang=submission.lang, code=submission.code, problem_id=submission.problem_id, author=self.new_user, judge_end_time=submission.judge_end_time, status=submission.status, status_percent=submission.status_percent, status_detail=submission.status_detail, status_time=submission.status_time, status_test=submission.status_test, status_memory=submission.status_memory) s.create_time = submission.create_time s.save(update_fields=["create_time"]) else: s = submission s.author = self.new_user s.save(update_fields=["author_id"]) invalidate_problem(s.problem) if s.status == SubmissionStatus.ACCEPTED: # Add reward _, created = ProblemRewardStatus.objects.get_or_create( problem_id=s.problem_id, user_id=self.new_user.id) if created: reward_problem_ac(self.new_user, s.problem.reward, s.problem_id) self.old_user.is_active = False self.old_user.save(update_fields=['is_active']) except: msg = traceback.format_exc() print(msg) send_mail(subject="Migrate fail notice", message=msg, from_email=None, recipient_list=settings.ADMIN_EMAIL_LIST, fail_silently=True)
def invalidate_contest(contest: Contest): invalidate_contest_participant(contest) invalidate_contest_problem(contest) for problem in contest.contest_problem_list: invalidate_problem(problem.problem)
def invalidate_contest(contest: Contest, sync=False): invalidate_contest_participant(contest, sync=sync) invalidate_problem( list(map(lambda p: p.problem_id, contest.contest_problem_list)), contest.id) cache.delete(CONTEST_FIRST_YES.format(contest.pk))
def run(*args): for problem in progressbar.progressbar(Problem.objects.all()): invalidate_problem(problem)