增加比赛倒计时的功能
This commit is contained in:
@@ -46,7 +46,7 @@ class Contest(models.Model):
|
||||
# 没有开始 返回1
|
||||
return 1
|
||||
elif self.end_time < now():
|
||||
# 已经结束 返回0
|
||||
# 已经结束 返回-1
|
||||
return -1
|
||||
else:
|
||||
# 正在进行 返回0
|
||||
|
||||
@@ -463,15 +463,12 @@ class ContestTimeAPIView(APIView):
|
||||
获取比赛开始或者结束的倒计时,返回毫秒数字
|
||||
"""
|
||||
def get(self, request):
|
||||
t = request.GET.get("type", "start")
|
||||
contest_id = request.GET.get("contest_id", -1)
|
||||
try:
|
||||
contest = Contest.objects.get(id=contest_id)
|
||||
except Contest.DoesNotExist:
|
||||
return error_response(u"比赛不存在")
|
||||
if t == "start":
|
||||
# 距离开始还有多长时间
|
||||
return success_response(int((contest.start_time - now()).total_seconds() * 1000))
|
||||
else:
|
||||
# 距离结束还有多长时间
|
||||
return success_response(int((contest.end_time - now()).total_seconds() * 1000))
|
||||
return success_response({"start": int((contest.start_time - now()).total_seconds() * 1000),
|
||||
"end": int((contest.end_time - now()).total_seconds() * 1000),
|
||||
"status": contest.status})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user