mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
为User problems_status 添加默认值,并精简了相关代码
This commit is contained in:
parent
21b18b8e97
commit
18e661ad68
19
account/migrations/0003_auto_20150915_2025.py
Normal file
19
account/migrations/0003_auto_20150915_2025.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0002_user_problems_status'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='problems_status',
|
||||
field=models.TextField(default=b'{}'),
|
||||
),
|
||||
]
|
@ -31,8 +31,7 @@ class User(AbstractBaseUser):
|
||||
# 0代表不是管理员 1是普通管理员 2是超级管理员
|
||||
admin_type = models.IntegerField(default=0)
|
||||
# JSON字典用来表示该用户的问题的解决状态 1为ac,2为正在进行
|
||||
problems_status = models.TextField(blank=True)
|
||||
|
||||
problems_status = models.TextField(default="{}")
|
||||
|
||||
USERNAME_FIELD = 'username'
|
||||
REQUIRED_FIELDS = []
|
||||
|
@ -43,10 +43,7 @@ class MessageQueue(object):
|
||||
except User.DoesNotExist:
|
||||
logger.warning("Submission user does not exist, submission_id: " + submission_id)
|
||||
continue
|
||||
if user.problems_status:
|
||||
problems_status = json.loads(user.problems_status)
|
||||
else:
|
||||
problems_status = {}
|
||||
problems_status = json.loads(user.problems_status)
|
||||
problems_status[str(problem.id)] = 1
|
||||
user.problems_status = json.dumps(problems_status)
|
||||
user.save()
|
||||
|
@ -282,7 +282,7 @@ def problem_list_page(request, page=1):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if request.user.is_authenticated() and request.user.problems_status:
|
||||
if request.user.is_authenticated():
|
||||
problems_status = json.loads(request.user.problems_status)
|
||||
else:
|
||||
problems_status = {}
|
||||
|
@ -47,10 +47,7 @@ class SubmissionAPIView(APIView):
|
||||
except Exception:
|
||||
return error_response(u"提交判题任务失败")
|
||||
# 修改用户解题状态
|
||||
if request.user.problems_status:
|
||||
problems_status = json.loads(request.user.problems_status)
|
||||
else:
|
||||
problems_status = {}
|
||||
problems_status = json.loads(request.user.problems_status)
|
||||
problems_status[str(data["problem_id"])] = 2
|
||||
request.user.problems_status = json.dumps(problems_status)
|
||||
request.user.save()
|
||||
|
Loading…
Reference in New Issue
Block a user