mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
contest type 的表示类型修改为常量
0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
This commit is contained in:
parent
fddd1d866e
commit
24758a3589
@ -7,6 +7,11 @@ from problem.models import AbstractProblem
|
|||||||
from group.models import Group
|
from group.models import Group
|
||||||
|
|
||||||
|
|
||||||
|
GROUP_CONTEST = 0
|
||||||
|
PUBLIC_CONTEST = 1
|
||||||
|
PASSWORD_PUBLIC_CONTEST = 2
|
||||||
|
|
||||||
|
|
||||||
class Contest(models.Model):
|
class Contest(models.Model):
|
||||||
title = models.CharField(max_length=40, unique=True)
|
title = models.CharField(max_length=40, unique=True)
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
@ -19,7 +24,8 @@ class Contest(models.Model):
|
|||||||
# 只能超级管理员创建公开赛,管理员只能创建小组内部的比赛
|
# 只能超级管理员创建公开赛,管理员只能创建小组内部的比赛
|
||||||
# 如果这一项不为空,即为有密码的公开赛,没有密码的可以为小组赛或者是公开赛(此时用比赛的类型来表示)
|
# 如果这一项不为空,即为有密码的公开赛,没有密码的可以为小组赛或者是公开赛(此时用比赛的类型来表示)
|
||||||
password = models.CharField(max_length=30, blank=True, null=True)
|
password = models.CharField(max_length=30, blank=True, null=True)
|
||||||
# 比赛的类型: 0 即为是小组赛,1 即为是无密码的公开赛,2 即为是有密码的公开赛
|
# 比赛的类型: 0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),
|
||||||
|
# 2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
|
||||||
contest_type = models.IntegerField()
|
contest_type = models.IntegerField()
|
||||||
# 开始时间
|
# 开始时间
|
||||||
start_time = models.DateTimeField()
|
start_time = models.DateTimeField()
|
||||||
|
@ -10,6 +10,7 @@ from account.models import User
|
|||||||
from group.models import Group
|
from group.models import Group
|
||||||
from contest.models import Contest, ContestProblem
|
from contest.models import Contest, ContestProblem
|
||||||
from .models import ContestSubmission
|
from .models import ContestSubmission
|
||||||
|
from .models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST
|
||||||
from announcement.models import Announcement
|
from announcement.models import Announcement
|
||||||
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
from decorators import check_user_contest_permission
|
from decorators import check_user_contest_permission
|
||||||
@ -35,12 +36,14 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
join_group_setting=0, visible=True,
|
join_group_setting=0, visible=True,
|
||||||
admin=user1)
|
admin=user1)
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
self.group_contest = Contest.objects.create(title="titley", description="descriptiony", mode=1,
|
self.group_contest = Contest.objects.create(title="titley", description="descriptiony", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -54,7 +57,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_global_contest_does_not_has_privileges(self):
|
def test_global_contest_does_not_has_privileges(self):
|
||||||
self.client.login(username="test2", password="testbb")
|
self.client.login(username="test2", password="testbb")
|
||||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 2,
|
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -62,7 +65,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_global_contest_password_exists(self):
|
def test_global_contest_password_exists(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 2,
|
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -70,7 +73,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_group_contest_group_at_least_one(self):
|
def test_group_contest_group_at_least_one(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": 0,
|
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": GROUP_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -78,7 +81,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_global_contest_successfully(self):
|
def test_global_contest_successfully(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "title1", "description": "description1", "mode": 1, "contest_type": 2,
|
data = {"title": "title1", "description": "description1", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -86,7 +89,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_group_contest_super_admin_successfully(self):
|
def test_group_contest_super_admin_successfully(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "title3", "description": "description3", "mode": 1, "contest_type": 0,
|
data = {"title": "title3", "description": "description3", "mode": 1, "contest_type": GROUP_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -94,7 +97,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_group_contest_admin_successfully(self):
|
def test_group_contest_admin_successfully(self):
|
||||||
self.client.login(username="test2", password="testbb")
|
self.client.login(username="test2", password="testbb")
|
||||||
data = {"title": "title6", "description": "description6", "mode": 2, "contest_type": 0,
|
data = {"title": "title6", "description": "description6", "mode": 2, "contest_type": GROUP_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "groups": [self.group.id], "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -102,7 +105,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_time_error(self):
|
def test_time_error(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "title2", "description": "description2", "mode": 1, "contest_type": 2,
|
data = {"title": "title2", "description": "description2", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T12:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T12:00:00.000Z",
|
||||||
"end_time": "2015-08-15T10:00:00.000Z", "password": "aabb", "visible": True}
|
"end_time": "2015-08-15T10:00:00.000Z", "password": "aabb", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -110,7 +113,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_contest_has_exists(self):
|
def test_contest_has_exists(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"title": "titlex", "description": "descriptionx", "mode": 1, "contest_type": 2,
|
data = {"title": "titlex", "description": "descriptionx", "mode": 1, "contest_type": PASSWORD_PUBLIC_CONTEST,
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "password": "aabb", "visible": True}
|
||||||
response = self.client.post(self.url, data=data)
|
response = self.client.post(self.url, data=data)
|
||||||
@ -126,7 +129,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_contest_does_not_exist(self):
|
def test_contest_does_not_exist(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.global_contest.id + 10, "title": "title2", "description": "description2", "mode": 1,
|
data = {"id": self.global_contest.id + 10, "title": "title2", "description": "description2", "mode": 1,
|
||||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||||
"visible": True}
|
"visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -135,7 +138,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_global_contest_successfully(self):
|
def test_edit_global_contest_successfully(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.global_contest.id, "title": "titlez", "description": "descriptionz", "mode": 1,
|
data = {"id": self.global_contest.id, "title": "titlez", "description": "descriptionz", "mode": 1,
|
||||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "password": "aabb",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "password": "aabb",
|
||||||
"visible": True}
|
"visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -146,7 +149,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_group_contest_successfully(self):
|
def test_edit_group_contest_successfully(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
||||||
"groups": [self.group.id], "visible": False}
|
"groups": [self.group.id], "visible": False}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -158,7 +161,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_group_contest_unsuccessfully(self):
|
def test_edit_group_contest_unsuccessfully(self):
|
||||||
self.client.login(username="test2", password="testbb")
|
self.client.login(username="test2", password="testbb")
|
||||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z",
|
||||||
"groups": [self.group.id], "visible": False}
|
"groups": [self.group.id], "visible": False}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -167,7 +170,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_group_at_least_one(self):
|
def test_edit_group_at_least_one(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
data = {"id": self.group_contest.id, "title": "titleyyy", "description": "descriptionyyyy", "mode": 1,
|
||||||
"contest_type": 0, "show_rank": True, "show_user_submission": True,
|
"contest_type": GROUP_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "visible": True}
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T13:00:00.000Z", "visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 1, "data": u"请至少选择一个小组"})
|
self.assertEqual(response.data, {"code": 1, "data": u"请至少选择一个小组"})
|
||||||
@ -175,7 +178,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_contest_has_exists(self):
|
def test_edit_contest_has_exists(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.global_contest.id, "title": "titley", "description": "descriptiony", "mode": 1,
|
data = {"id": self.global_contest.id, "title": "titley", "description": "descriptiony", "mode": 1,
|
||||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||||
"visible": True}
|
"visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -184,7 +187,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_global_contest_does_not_has_privileges(self):
|
def test_edit_global_contest_does_not_has_privileges(self):
|
||||||
self.client.login(username="test2", password="testbb")
|
self.client.login(username="test2", password="testbb")
|
||||||
data = {"id": self.global_contest.id, "title": "titlexxxxxxxxx", "description": "descriptionxxxxxx", "mode": 1,
|
data = {"id": self.global_contest.id, "title": "titlexxxxxxxxx", "description": "descriptionxxxxxx", "mode": 1,
|
||||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
"start_time": "2015-08-15T10:00:00.000Z", "end_time": "2015-08-15T12:00:00.000Z", "password": "aabb",
|
||||||
"visible": True}
|
"visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -193,8 +196,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_global_contest_password_exists(self):
|
def test_edit_global_contest_password_exists(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.global_contest.id, "title": "title0", "description": "description0", "mode": 1,
|
data = {"id": self.global_contest.id, "title": "title0", "description": "description0", "mode": 1,
|
||||||
"contest_type": 2,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
||||||
"show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
|
||||||
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
"end_time": "2015-08-15T12:00:00.000Z", "visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 1, "data": u"此比赛为有密码的公开赛,密码不可为空"})
|
self.assertEqual(response.data, {"code": 1, "data": u"此比赛为有密码的公开赛,密码不可为空"})
|
||||||
@ -202,7 +204,7 @@ class ContestAdminAPITest(APITestCase):
|
|||||||
def test_edit_time_error(self):
|
def test_edit_time_error(self):
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
data = {"id": self.global_contest.id, "title": "titleaaaa", "description": "descriptionaaaaa", "mode": 1,
|
data = {"id": self.global_contest.id, "title": "titleaaaa", "description": "descriptionaaaaa", "mode": 1,
|
||||||
"contest_type": 2, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
||||||
"start_time": "2015-08-15T12:00:00.000Z", "end_time": "2015-08-15T10:00:00.000Z", "password": "aabb",
|
"start_time": "2015-08-15T12:00:00.000Z", "end_time": "2015-08-15T10:00:00.000Z", "password": "aabb",
|
||||||
"visible": True}
|
"visible": True}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
@ -245,7 +247,8 @@ class ContestProblemAdminAPItEST(APITestCase):
|
|||||||
self.user3.save()
|
self.user3.save()
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -414,7 +417,8 @@ class ContestPasswordVerifyAPITest(APITestCase):
|
|||||||
self.user2.save()
|
self.user2.save()
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -453,7 +457,8 @@ class ContestPageTest(TestCase):
|
|||||||
self.user1.save()
|
self.user1.save()
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -476,7 +481,8 @@ class ContestProblemPageTest(TestCase):
|
|||||||
self.user1.save()
|
self.user1.save()
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -519,7 +525,8 @@ class ContestProblemListPageTest(TestCase):
|
|||||||
self.user1.save()
|
self.user1.save()
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
@ -555,7 +562,8 @@ class ContestListPageTest(TestCase):
|
|||||||
self.url = reverse('contest_list_page')
|
self.url = reverse('contest_list_page')
|
||||||
self.client.login(username="test1", password="testaa")
|
self.client.login(username="test1", password="testaa")
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
|
@ -18,6 +18,7 @@ from group.models import Group
|
|||||||
from announcement.models import Announcement
|
from announcement.models import Announcement
|
||||||
|
|
||||||
from .models import Contest, ContestProblem, ContestSubmission
|
from .models import Contest, ContestProblem, ContestSubmission
|
||||||
|
from .models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST
|
||||||
from .decorators import check_user_contest_permission
|
from .decorators import check_user_contest_permission
|
||||||
from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer,
|
from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer,
|
||||||
CreateContestProblemSerializer, ContestProblemSerializer,
|
CreateContestProblemSerializer, ContestProblemSerializer,
|
||||||
@ -37,17 +38,18 @@ class ContestAdminAPIView(APIView):
|
|||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
data = serializer.data
|
data = serializer.data
|
||||||
groups = []
|
groups = []
|
||||||
# 首先判断比赛的类型: 0 即为是小组赛,1 即为是无密码的公开赛,2 即为是有密码的公开赛
|
# 首先判断比赛的类型: 0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),
|
||||||
|
# 2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
|
||||||
# 此时为有密码的公开赛,并且此时只能超级管理员才有权限此创建比赛
|
# 此时为有密码的公开赛,并且此时只能超级管理员才有权限此创建比赛
|
||||||
if data["contest_type"] in [1, 2]:
|
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]:
|
||||||
if request.user.admin_type != SUPER_ADMIN:
|
if request.user.admin_type != SUPER_ADMIN:
|
||||||
return error_response(u"只有超级管理员才可创建公开赛")
|
return error_response(u"只有超级管理员才可创建公开赛")
|
||||||
if data["contest_type"] == 2:
|
if data["contest_type"] == PASSWORD_PUBLIC_CONTEST:
|
||||||
if not data["password"]:
|
if not data["password"]:
|
||||||
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
||||||
|
|
||||||
# 没有密码的公开赛 没有密码的小组赛
|
# 没有密码的公开赛 没有密码的小组赛
|
||||||
elif data["contest_type"] == 0:
|
elif data["contest_type"] == GROUP_CONTEST:
|
||||||
if request.user.admin_type == SUPER_ADMIN:
|
if request.user.admin_type == SUPER_ADMIN:
|
||||||
groups = Group.objects.filter(id__in=data["groups"])
|
groups = Group.objects.filter(id__in=data["groups"])
|
||||||
else:
|
else:
|
||||||
@ -92,13 +94,13 @@ class ContestAdminAPIView(APIView):
|
|||||||
return error_response(u"该比赛名称已经存在")
|
return error_response(u"该比赛名称已经存在")
|
||||||
except Contest.DoesNotExist:
|
except Contest.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
if data["contest_type"] in [1, 2]:
|
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]:
|
||||||
if request.user.admin_type != SUPER_ADMIN:
|
if request.user.admin_type != SUPER_ADMIN:
|
||||||
return error_response(u"只有超级管理员才可创建公开赛")
|
return error_response(u"只有超级管理员才可创建公开赛")
|
||||||
if data["contest_type"] == 2:
|
if data["contest_type"] == PASSWORD_PUBLIC_CONTEST:
|
||||||
if not data["password"]:
|
if not data["password"]:
|
||||||
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
||||||
elif data["contest_type"] == 0:
|
elif data["contest_type"] == GROUP_CONTEST:
|
||||||
if request.user.admin_type == SUPER_ADMIN:
|
if request.user.admin_type == SUPER_ADMIN:
|
||||||
groups = Group.objects.filter(id__in=data["groups"])
|
groups = Group.objects.filter(id__in=data["groups"])
|
||||||
else:
|
else:
|
||||||
@ -256,7 +258,7 @@ class ContestPasswordVerifyAPIView(APIView):
|
|||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
data = request.data
|
data = request.data
|
||||||
try:
|
try:
|
||||||
contest = Contest.objects.get(id=data["contest_id"], contest_type=2)
|
contest = Contest.objects.get(id=data["contest_id"], contest_type=PASSWORD_PUBLIC_CONTEST)
|
||||||
except Contest.DoesNotExist:
|
except Contest.DoesNotExist:
|
||||||
return error_response(u"比赛不存在")
|
return error_response(u"比赛不存在")
|
||||||
|
|
||||||
@ -355,7 +357,7 @@ def contest_list_page(request, page=1):
|
|||||||
# 筛选我能参加的比赛
|
# 筛选我能参加的比赛
|
||||||
join = request.GET.get("join", None)
|
join = request.GET.get("join", None)
|
||||||
if join:
|
if join:
|
||||||
contests = contests.filter(Q(contest_type__in=[1, 2]) | Q(groups__in=request.user.group_set.all())). \
|
contests = contests.filter(Q(contest_type__in=[PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]) | Q(groups__in=request.user.group_set.all())). \
|
||||||
filter(end_time__gt=datetime.datetime.now(), start_time__lt=datetime.datetime.now())
|
filter(end_time__gt=datetime.datetime.now(), start_time__lt=datetime.datetime.now())
|
||||||
|
|
||||||
paginator = Paginator(contests, 20)
|
paginator = Paginator(contests, 20)
|
||||||
|
@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
from problem.models import Problem
|
from problem.models import Problem
|
||||||
from contest.models import Contest, ContestProblem
|
from contest.models import Contest, ContestProblem
|
||||||
|
from contest.models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST
|
||||||
from submission.models import Submission
|
from submission.models import Submission
|
||||||
from rest_framework.test import APITestCase, APIClient
|
from rest_framework.test import APITestCase, APIClient
|
||||||
|
|
||||||
@ -20,7 +21,8 @@ class ContestSubmissionAPITest(APITestCase):
|
|||||||
self.user2.set_password("testbb")
|
self.user2.set_password("testbb")
|
||||||
self.user2.save()
|
self.user2.save()
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=1, show_rank=True, show_user_submission=True,
|
contest_type=PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-30T12:00:00.000Z",
|
end_time="2015-08-30T12:00:00.000Z",
|
||||||
created_by=User.objects.get(username="test1"))
|
created_by=User.objects.get(username="test1"))
|
||||||
@ -70,7 +72,8 @@ class ContestProblemMySubmissionListTest(TestCase):
|
|||||||
self.user2.set_password("testbb")
|
self.user2.set_password("testbb")
|
||||||
self.user2.save()
|
self.user2.save()
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=1, show_rank=True, show_user_submission=True,
|
contest_type=PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-30T12:00:00.000Z",
|
end_time="2015-08-30T12:00:00.000Z",
|
||||||
created_by=User.objects.get(username="test1"))
|
created_by=User.objects.get(username="test1"))
|
||||||
@ -104,7 +107,8 @@ class SubmissionAPITest(APITestCase):
|
|||||||
self.userS.set_password("testbb")
|
self.userS.set_password("testbb")
|
||||||
self.userS.save()
|
self.userS.save()
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=self.userS
|
password="aacc", created_by=self.userS
|
||||||
|
@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
from problem.models import Problem
|
from problem.models import Problem
|
||||||
from contest.models import Contest
|
from contest.models import Contest
|
||||||
|
from contest.models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST
|
||||||
from submission.models import Submission
|
from submission.models import Submission
|
||||||
from rest_framework.test import APITestCase, APIClient
|
from rest_framework.test import APITestCase, APIClient
|
||||||
|
|
||||||
@ -82,7 +83,8 @@ class SubmissionAPITest(APITestCase):
|
|||||||
hint="hint1",
|
hint="hint1",
|
||||||
created_by=User.objects.get(username="test2"))
|
created_by=User.objects.get(username="test2"))
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test2"))
|
password="aacc", created_by=User.objects.get(username="test2"))
|
||||||
@ -151,7 +153,8 @@ class SubmissionAdminAPITest(APITestCase):
|
|||||||
hint="hint1",
|
hint="hint1",
|
||||||
created_by=self.user)
|
created_by=self.user)
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=self.user)
|
password="aacc", created_by=self.user)
|
||||||
@ -190,7 +193,8 @@ class SubmissionPageTest(TestCase):
|
|||||||
hint="hint1",
|
hint="hint1",
|
||||||
created_by=User.objects.get(username="test1"))
|
created_by=User.objects.get(username="test1"))
|
||||||
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
self.global_contest = Contest.objects.create(title="titlex", description="descriptionx", mode=1,
|
||||||
contest_type=2, show_rank=True, show_user_submission=True,
|
contest_type=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
||||||
|
show_user_submission=True,
|
||||||
start_time="2015-08-15T10:00:00.000Z",
|
start_time="2015-08-15T10:00:00.000Z",
|
||||||
end_time="2015-08-15T12:00:00.000Z",
|
end_time="2015-08-15T12:00:00.000Z",
|
||||||
password="aacc", created_by=User.objects.get(username="test1"))
|
password="aacc", created_by=User.objects.get(username="test1"))
|
||||||
|
Loading…
Reference in New Issue
Block a user