移除 OI 残留:UserProfile 的 oi_problems_status / total_score / add_score
判题不再写入 OI 相关状态后,UserProfile 上的 OI 字段永远为空/为 0: - 删除 oi_problems_status、total_score 两列及 add_score() 方法 - ProfileProblemDisplayIDRefreshAPI 去掉 oi_problems 合并分支 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 6.0.4 on 2026-07-04 17:32
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0007_rename_admin_to_student_admin'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='userprofile',
|
||||
name='oi_problems_status',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='userprofile',
|
||||
name='total_score',
|
||||
),
|
||||
]
|
||||
@@ -108,8 +108,6 @@ class UserProfile(models.Model):
|
||||
# }
|
||||
# }
|
||||
acm_problems_status = JSONField(default=dict, db_default=models.Value({}, output_field=models.JSONField()))
|
||||
# like acm_problems_status, merely add "score" field
|
||||
oi_problems_status = JSONField(default=dict, db_default=models.Value({}, output_field=models.JSONField()))
|
||||
|
||||
real_name = models.TextField(null=True)
|
||||
avatar = models.TextField(default=f"{settings.AVATAR_URI_PREFIX}/default.png")
|
||||
@@ -119,10 +117,7 @@ class UserProfile(models.Model):
|
||||
school = models.TextField(null=True)
|
||||
major = models.TextField(null=True)
|
||||
language = models.TextField(null=True)
|
||||
# for ACM
|
||||
accepted_number = models.IntegerField(default=0, db_default=0)
|
||||
# for OI
|
||||
total_score = models.BigIntegerField(default=0, db_default=0)
|
||||
submission_number = models.IntegerField(default=0, db_default=0)
|
||||
|
||||
def add_accepted_problem_number(self):
|
||||
@@ -133,11 +128,5 @@ class UserProfile(models.Model):
|
||||
self.submission_number = models.F("submission_number") + 1
|
||||
self.save(update_fields=["submission_number"])
|
||||
|
||||
# 计算总分时, 应先减掉上次该题所得分数, 然后再加上本次所得分数
|
||||
def add_score(self, this_time_score, last_time_score=None):
|
||||
last_time_score = last_time_score or 0
|
||||
self.total_score = models.F("total_score") - last_time_score + this_time_score
|
||||
self.save(update_fields=["total_score"])
|
||||
|
||||
class Meta:
|
||||
db_table = "user_profile"
|
||||
|
||||
@@ -517,17 +517,14 @@ class ProfileProblemDisplayIDRefreshAPI(AsyncAPIView):
|
||||
async def get(self, request):
|
||||
profile = await UserProfile.objects.aget(user=request.user)
|
||||
acm_problems = profile.acm_problems_status.get("problems", {})
|
||||
oi_problems = profile.oi_problems_status.get("problems", {})
|
||||
ids = list(acm_problems.keys()) + list(oi_problems.keys())
|
||||
ids = list(acm_problems.keys())
|
||||
if not ids:
|
||||
return self.success()
|
||||
display_ids = [did async for did in Problem.objects.filter(id__in=ids, visible=True).values_list("_id", flat=True)]
|
||||
id_map = dict(zip(ids, display_ids))
|
||||
for k, v in acm_problems.items():
|
||||
v["_id"] = id_map[k]
|
||||
for k, v in oi_problems.items():
|
||||
v["_id"] = id_map[k]
|
||||
await profile.asave(update_fields=["acm_problems_status", "oi_problems_status"])
|
||||
await profile.asave(update_fields=["acm_problems_status"])
|
||||
return self.success()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user