mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
使用 model 的 instance method 进行比赛状态的判断
This commit is contained in:
parent
1c37c4bfb6
commit
76b28f2da2
@ -74,7 +74,7 @@ def check_user_contest_permission(func):
|
|||||||
{"reason": "group_limited", "show_tab": False, "contest": contest})
|
{"reason": "group_limited", "show_tab": False, "contest": contest})
|
||||||
|
|
||||||
# 比赛没有开始
|
# 比赛没有开始
|
||||||
if contest.start_time > now():
|
if contest.status == 1:
|
||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
return error_response(u"比赛还没有开始")
|
return error_response(u"比赛还没有开始")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
from account.models import User
|
from account.models import User
|
||||||
from problem.models import AbstractProblem
|
from problem.models import AbstractProblem
|
||||||
@ -34,6 +35,18 @@ class Contest(models.Model):
|
|||||||
# 是否可见 false的话相当于删除
|
# 是否可见 false的话相当于删除
|
||||||
visible = models.BooleanField(default=True)
|
visible = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
if self.start_time > now():
|
||||||
|
# 没有开始 返回1
|
||||||
|
return 1
|
||||||
|
elif self.end_time < now():
|
||||||
|
# 已经结束 返回0
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
# 正在进行 返回0
|
||||||
|
return 0
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "contest"
|
db_table = "contest"
|
||||||
|
|
||||||
|
|||||||
@ -4,19 +4,23 @@ from django.utils.timezone import now
|
|||||||
|
|
||||||
|
|
||||||
def get_contest_status(contest):
|
def get_contest_status(contest):
|
||||||
if contest.start_time > now():
|
status = contest.status
|
||||||
|
if status == 1:
|
||||||
return "没有开始"
|
return "没有开始"
|
||||||
if contest.end_time < now():
|
elif status == -1:
|
||||||
return "已经结束"
|
return "已经结束"
|
||||||
return "正在进行"
|
else:
|
||||||
|
return "正在进行"
|
||||||
|
|
||||||
|
|
||||||
def get_contest_status_color(contest):
|
def get_contest_status_color(contest):
|
||||||
if contest.start_time > now():
|
status = contest.status
|
||||||
|
if status == 1:
|
||||||
return "info"
|
return "info"
|
||||||
if contest.end_time < now():
|
elif status == -1:
|
||||||
return "warning"
|
return "warning"
|
||||||
return "success"
|
else:
|
||||||
|
return "success"
|
||||||
|
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user