Skip to content

Commit

Permalink
修复没有点击操作时产生缓存空的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
InitialMoon committed Aug 24, 2024
1 parent 5641bc7 commit fd78ec4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
3 changes: 2 additions & 1 deletion contest/contest/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def _debug_only(*args) -> tuple:
}
}

# 防止本地注册表出现损坏导致的MIME类型解析错误,导致后端无法处理JS文件,有MIME报错的时候可以解除注释然后强制刷新前端运行看看
# 防止本地注册表出现损坏导致的MIME类型解析错误,导致后端无法处理JS文件
# 有MIME报错的时候可以解除注释然后强制刷新前端运行看看
# 这个用法已经被取消,建议不要使用,而是更改注册表.js的属性
# import mimetypes

Expand Down
1 change: 1 addition & 0 deletions contest/quiz/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def test_contest_update_view(self):

def test_bad_contest_update(self):
"""暂存非法数据
这里每次更新的时候没有写入后端,所以测试的话获取的应该是不对的,这里就先不要测了
"""
self.client.force_login(self.user)
Expand Down
39 changes: 20 additions & 19 deletions contest/quiz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,28 +255,29 @@ def contest_submit(request: AuthenticatedHttpRequest) -> HttpResponse:
# 从 Redis 获取现有的答案缓存
cached_answers = cache.get(cache_key, {})

for question_id, choice_id in cached_answers.items():
# Filter out tokens
if not question_id.startswith("question-"):
continue

if not isinstance(choice_id, str) or not choice_id.startswith("choice-"):
return HttpResponseBadRequest(
f"Invalid choice ID “{choice_id}” for “{question_id}”."
)
if cached_answers is not None:
for question_id, choice_id in cached_answers.items():
# Filter out tokens
if not question_id.startswith("question-"):
continue

answer: DraftAnswer = get_object_or_404(
draft_response.answer_set,
question_id=int(question_id.removeprefix("question-")),
)
if not isinstance(choice_id, str) or not choice_id.startswith("choice-"):
return HttpResponseBadRequest(
f"Invalid choice ID “{choice_id}” for “{question_id}”."
)

answer.choice = get_object_or_404(
Choice.objects,
pk=int(choice_id.removeprefix("choice-")),
question=answer.question,
)
answer: DraftAnswer = get_object_or_404(
draft_response.answer_set,
question_id=int(question_id.removeprefix("question-")),
)

answer.save()
answer.choice = get_object_or_404(
Choice.objects,
pk=int(choice_id.removeprefix("choice-")),
question=answer.question,
)

answer.save()

# 1. Convert from draft
response, answers = student.draft_response.finalize(submit_at=timezone.now())
Expand Down

0 comments on commit fd78ec4

Please sign in to comment.