mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
修改拼写 PASSWORD_PUBLIC_CONTEST -> PASSWORD_PROTECTED_CONTEST
This commit is contained in:
parent
63d0cc37f8
commit
ee4782b474
@ -6,10 +6,9 @@ from account.models import User
|
|||||||
from problem.models import AbstractProblem
|
from problem.models import AbstractProblem
|
||||||
from group.models import Group
|
from group.models import Group
|
||||||
|
|
||||||
|
|
||||||
GROUP_CONTEST = 0
|
GROUP_CONTEST = 0
|
||||||
PUBLIC_CONTEST = 1
|
PUBLIC_CONTEST = 1
|
||||||
PASSWORD_PUBLIC_CONTEST = 2
|
PASSWORD_PROTECTED_CONTEST = 2
|
||||||
|
|
||||||
|
|
||||||
class Contest(models.Model):
|
class Contest(models.Model):
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.test import TestCase, Client
|
from django.test import TestCase, Client
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
from rest_framework.test import APITestCase, APIClient
|
from rest_framework.test import APITestCase, APIClient
|
||||||
|
|
||||||
from account.models import User
|
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 .models import GROUP_CONTEST, PASSWORD_PROTECTED_CONTEST
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class ContestAdminAPITest(APITestCase):
|
class ContestAdminAPITest(APITestCase):
|
||||||
@ -36,13 +33,13 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -57,7 +54,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": PASSWORD_PUBLIC_CONTEST,
|
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -65,7 +62,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": PASSWORD_PUBLIC_CONTEST,
|
data = {"title": "title0", "description": "description0", "mode": 1, "contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -81,7 +78,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": PASSWORD_PUBLIC_CONTEST,
|
data = {"title": "title1", "description": "description1", "mode": 1, "contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -105,7 +102,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": PASSWORD_PUBLIC_CONTEST,
|
data = {"title": "title2", "description": "description2", "mode": 1, "contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -113,7 +110,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": PASSWORD_PUBLIC_CONTEST,
|
data = {"title": "titlex", "description": "descriptionx", "mode": 1, "contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -129,7 +126,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -138,7 +135,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -178,7 +175,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -187,7 +184,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -196,7 +193,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True, "start_time": "2015-08-15T10:00:00.000Z",
|
"contest_type": PASSWORD_PROTECTED_CONTEST, "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"此比赛为有密码的公开赛,密码不可为空"})
|
||||||
@ -204,7 +201,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": PASSWORD_PUBLIC_CONTEST, "show_rank": True, "show_user_submission": True,
|
"contest_type": PASSWORD_PROTECTED_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)
|
||||||
@ -247,7 +244,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -417,7 +414,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -457,7 +454,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -481,7 +478,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -525,7 +522,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
@ -562,7 +559,7 @@ 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=PASSWORD_PUBLIC_CONTEST, show_rank=True,
|
contest_type=PASSWORD_PROTECTED_CONTEST, show_rank=True,
|
||||||
show_user_submission=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",
|
||||||
|
@ -1,28 +1,25 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
from functools import wraps
|
|
||||||
from django.utils.timezone import now
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.utils import dateparse
|
from django.utils import dateparse
|
||||||
from django.db.models import Q, Count, Sum
|
from django.db.models import Q, Sum
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from utils.shortcuts import (serializer_invalid_response, error_response,
|
|
||||||
success_response, paginate, rand_str, error_page)
|
|
||||||
|
|
||||||
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN, User
|
from utils.shortcuts import (serializer_invalid_response, error_response,
|
||||||
|
success_response, paginate, error_page)
|
||||||
|
from account.models import SUPER_ADMIN, User
|
||||||
from account.decorators import login_required
|
from account.decorators import login_required
|
||||||
from group.models import Group
|
from group.models import Group
|
||||||
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 .models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PROTECTED_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,
|
||||||
EditContestProblemSerializer, ContestPasswordVerifySerializer,
|
ContestPasswordVerifySerializer,
|
||||||
EditContestProblemSerializer)
|
EditContestProblemSerializer)
|
||||||
|
|
||||||
|
|
||||||
@ -41,10 +38,10 @@ class ContestAdminAPIView(APIView):
|
|||||||
# 首先判断比赛的类型: 0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),
|
# 首先判断比赛的类型: 0 即为是小组赛(GROUP_CONTEST),1 即为是无密码的公开赛(PUBLIC_CONTEST),
|
||||||
# 2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
|
# 2 即为是有密码的公开赛(PASSWORD_PUBLIC_CONTEST)
|
||||||
# 此时为有密码的公开赛,并且此时只能超级管理员才有权限此创建比赛
|
# 此时为有密码的公开赛,并且此时只能超级管理员才有权限此创建比赛
|
||||||
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]:
|
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PROTECTED_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"] == PASSWORD_PUBLIC_CONTEST:
|
if data["contest_type"] == PASSWORD_PROTECTED_CONTEST:
|
||||||
if not data["password"]:
|
if not data["password"]:
|
||||||
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
||||||
|
|
||||||
@ -94,10 +91,10 @@ class ContestAdminAPIView(APIView):
|
|||||||
return error_response(u"该比赛名称已经存在")
|
return error_response(u"该比赛名称已经存在")
|
||||||
except Contest.DoesNotExist:
|
except Contest.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PUBLIC_CONTEST]:
|
if data["contest_type"] in [PUBLIC_CONTEST, PASSWORD_PROTECTED_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"] == PASSWORD_PUBLIC_CONTEST:
|
if data["contest_type"] == PASSWORD_PROTECTED_CONTEST:
|
||||||
if not data["password"]:
|
if not data["password"]:
|
||||||
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
return error_response(u"此比赛为有密码的公开赛,密码不可为空")
|
||||||
elif data["contest_type"] == GROUP_CONTEST:
|
elif data["contest_type"] == GROUP_CONTEST:
|
||||||
@ -258,7 +255,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=PASSWORD_PUBLIC_CONTEST)
|
contest = Contest.objects.get(id=data["contest_id"], contest_type=PASSWORD_PROTECTED_CONTEST)
|
||||||
except Contest.DoesNotExist:
|
except Contest.DoesNotExist:
|
||||||
return error_response(u"比赛不存在")
|
return error_response(u"比赛不存在")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user