Accept Merge Request #161 终于可以合并了..... : (dev-sxw -> dev)
Merge Request: 终于可以合并了..... Created By: @esp Accepted By: @hohoTT URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/161
This commit is contained in:
@@ -140,12 +140,12 @@ class UserAdminAPITest(APITestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = APIClient()
|
self.client = APIClient()
|
||||||
self.url = reverse("user_admin_api")
|
self.url = reverse("user_admin_api")
|
||||||
user = User.objects.create(username="testx", real_name="xx", admin_type=SUPER_ADMIN)
|
self.user1 = User.objects.create(username="testx", real_name="xx", admin_type=SUPER_ADMIN)
|
||||||
user.set_password("testxx")
|
self.user1.set_password("testxx")
|
||||||
user.save()
|
self.user1.save()
|
||||||
user = User.objects.create(username="testy", real_name="yy", admin_type=SUPER_ADMIN)
|
self.user = User.objects.create(username="testy", real_name="yy", admin_type=SUPER_ADMIN)
|
||||||
user.set_password("testyy")
|
self.user.set_password("testyy")
|
||||||
user.save()
|
self.user.save()
|
||||||
self.client.login(username="testx", password="testxx")
|
self.client.login(username="testx", password="testxx")
|
||||||
|
|
||||||
# 以下是编辑用户的测试
|
# 以下是编辑用户的测试
|
||||||
@@ -164,19 +164,19 @@ class UserAdminAPITest(APITestCase):
|
|||||||
self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"})
|
self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"})
|
||||||
|
|
||||||
def test_username_exists(self):
|
def test_username_exists(self):
|
||||||
data = {"id": 1, "username": "testy", "real_name": "test00",
|
data = {"id": self.user.id, "username": "testx", "real_name": "test00",
|
||||||
"password": "testaa", "email": "60@qq.com", "admin_type": "2"}
|
"password": "testaa", "email": "60@qq.com", "admin_type": "2"}
|
||||||
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"昵称已经存在"})
|
||||||
|
|
||||||
def test_user_edit_not_password_successfully(self):
|
def test_user_edit_not_password_successfully(self):
|
||||||
data = {"id": 1, "username": "test0", "real_name": "test00",
|
data = {"id": self.user.id, "username": "test0", "real_name": "test00",
|
||||||
"email": "60@qq.com", "admin_type": "2"}
|
"email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 0)
|
self.assertEqual(response.data["code"], 0)
|
||||||
|
|
||||||
def test_user_edit_change_password_successfully(self):
|
def test_user_edit_change_password_successfully(self):
|
||||||
data = {"id": 1, "username": "test0", "real_name": "test00", "password": "111111",
|
data = {"id": self.user.id, "username": "test0", "real_name": "test00", "password": "111111",
|
||||||
"email": "60@qq.com", "admin_type": "2"}
|
"email": "60@qq.com", "admin_type": "2"}
|
||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 0)
|
self.assertEqual(response.data["code"], 0)
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ class ContestProblemAdminAPItEST(APITestCase):
|
|||||||
|
|
||||||
def test_query_contest_problem_exists_by_contest_id(self):
|
def test_query_contest_problem_exists_by_contest_id(self):
|
||||||
self.client.login(username="test3", password="testaa")
|
self.client.login(username="test3", password="testaa")
|
||||||
response = self.client.get(self.url + "?contest_id=1")
|
response = self.client.get(self.url + "?contest_id="+ str(self.global_contest.id))
|
||||||
self.assertEqual(response.data["code"], 0)
|
self.assertEqual(response.data["code"], 0)
|
||||||
self.assertEqual(len(response.data["data"]), 0)
|
self.assertEqual(len(response.data["data"]), 0)
|
||||||
|
|
||||||
|
|||||||
@@ -396,10 +396,10 @@ def _cmp(x, y):
|
|||||||
def contest_rank_page(request, contest_id):
|
def contest_rank_page(request, contest_id):
|
||||||
contest = Contest.objects.get(id=contest_id)
|
contest = Contest.objects.get(id=contest_id)
|
||||||
contest_problems = ContestProblem.objects.filter(contest=contest).order_by("sort_index")
|
contest_problems = ContestProblem.objects.filter(contest=contest).order_by("sort_index")
|
||||||
result = ContestSubmission.objects.values("user_id").annotate(total_submit=Count("user_id"))
|
result = ContestSubmission.objects.filter(contest=contest).values("user_id").annotate(total_submit=Sum("total_submission_number"))
|
||||||
for i in range(0, len(result)):
|
for i in range(0, len(result)):
|
||||||
# 这个人所有的提交
|
# 这个人所有的提交
|
||||||
submissions = ContestSubmission.objects.filter(user_id=result[i]["user_id"])
|
submissions = ContestSubmission.objects.filter(user_id=result[i]["user_id"], contest_id=contest_id)
|
||||||
result[i]["submissions"] = {}
|
result[i]["submissions"] = {}
|
||||||
for item in submissions:
|
for item in submissions:
|
||||||
result[i]["submissions"][item.problem_id] = item
|
result[i]["submissions"][item.problem_id] = item
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class EditGroupSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
class CreateJoinGroupRequestSerializer(serializers.Serializer):
|
class CreateJoinGroupRequestSerializer(serializers.Serializer):
|
||||||
group_id = serializers.IntegerField()
|
group_id = serializers.IntegerField()
|
||||||
message = serializers.CharField(max_length=30)
|
message = serializers.CharField(max_length=30, required=False)
|
||||||
|
|
||||||
|
|
||||||
class JoinGroupRequestSerializer(serializers.ModelSerializer):
|
class JoinGroupRequestSerializer(serializers.ModelSerializer):
|
||||||
|
|||||||
@@ -183,6 +183,8 @@ class JoinGroupAPIView(APIView):
|
|||||||
else:
|
else:
|
||||||
return error_response(u"你已经是小组成员了")
|
return error_response(u"你已经是小组成员了")
|
||||||
elif group.join_group_setting == 1:
|
elif group.join_group_setting == 1:
|
||||||
|
if not data["message"]:
|
||||||
|
return error_response(u"message : 该字段是必填项。")
|
||||||
try:
|
try:
|
||||||
JoinGroupRequest.objects.get(user=request.user, group=group, status=False)
|
JoinGroupRequest.objects.get(user=request.user, group=group, status=False)
|
||||||
return error_response(u"你已经提交过申请了,请等待审核")
|
return error_response(u"你已经提交过申请了,请等待审核")
|
||||||
@@ -295,6 +297,7 @@ def group_page(request, group_id):
|
|||||||
return error_page(request, u"小组不存在")
|
return error_page(request, u"小组不存在")
|
||||||
return render(request, "oj/group/group.html", {"group": group})
|
return render(request, "oj/group/group.html", {"group": group})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def application_list_page(request, group_id):
|
def application_list_page(request, group_id):
|
||||||
try:
|
try:
|
||||||
@@ -305,6 +308,7 @@ def application_list_page(request, group_id):
|
|||||||
return render(request, "oj/group/my_application_list.html",
|
return render(request, "oj/group/my_application_list.html",
|
||||||
{"group": group, "applications": applications})
|
{"group": group, "applications": applications})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def application_page(request, request_id):
|
def application_page(request, request_id):
|
||||||
try:
|
try:
|
||||||
@@ -312,4 +316,4 @@ def application_page(request, request_id):
|
|||||||
except JoinGroupRequest.DoesNotExist:
|
except JoinGroupRequest.DoesNotExist:
|
||||||
return error_page(request, u"申请不存在")
|
return error_page(request, u"申请不存在")
|
||||||
return render(request, "oj/group/my_application.html",
|
return render(request, "oj/group/my_application.html",
|
||||||
{"application": application})
|
{"application": application})
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class MessageQueue(object):
|
|||||||
try:
|
try:
|
||||||
contest_submission = ContestSubmission.objects.get(user_id=submission.user_id, contest=contest,
|
contest_submission = ContestSubmission.objects.get(user_id=submission.user_id, contest=contest,
|
||||||
problem_id=contest_problem.id)
|
problem_id=contest_problem.id)
|
||||||
|
# 提交次数加1
|
||||||
|
contest_submission.total_submission_number += 1
|
||||||
|
|
||||||
if submission.result == result["accepted"]:
|
if submission.result == result["accepted"]:
|
||||||
|
|
||||||
@@ -65,13 +67,10 @@ class MessageQueue(object):
|
|||||||
contest_submission.total_time += int((submission.create_time - contest.start_time).total_seconds() / 60)
|
contest_submission.total_time += int((submission.create_time - contest.start_time).total_seconds() / 60)
|
||||||
# 标记为已经通过
|
# 标记为已经通过
|
||||||
contest_submission.ac = True
|
contest_submission.ac = True
|
||||||
# 提交次数加1
|
|
||||||
contest_submission.total_submission_number += 1
|
|
||||||
# contest problem ac 计数器加1
|
# contest problem ac 计数器加1
|
||||||
contest_problem.total_accepted_number += 1
|
contest_problem.total_accepted_number += 1
|
||||||
else:
|
else:
|
||||||
# 如果这个提交是错误的,就罚时20分钟
|
# 如果这个提交是错误的,就罚时20分钟
|
||||||
contest_submission.ac = False
|
|
||||||
contest_submission.total_time += 20
|
contest_submission.total_time += 20
|
||||||
contest_submission.save()
|
contest_submission.save()
|
||||||
contest_problem.save()
|
contest_problem.save()
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class ProblemAdminTest(APITestCase):
|
|||||||
self.assertEqual(response.data, {"code": 1, "data": u"题目不存在"})
|
self.assertEqual(response.data, {"code": 1, "data": u"题目不存在"})
|
||||||
|
|
||||||
def test_query_problem_exists(self):
|
def test_query_problem_exists(self):
|
||||||
data = {"problem_id": 1}
|
data = {"problem_id": self.problem.id}
|
||||||
response = self.client.get(self.url, data=data)
|
response = self.client.get(self.url, data=data)
|
||||||
self.assertEqual(response.data["code"], 0)
|
self.assertEqual(response.data["code"], 0)
|
||||||
|
|
||||||
|
|||||||
@@ -185,8 +185,12 @@ class TestCaseUploadAPIView(APIView):
|
|||||||
os.mkdir(test_case_dir)
|
os.mkdir(test_case_dir)
|
||||||
for name in l:
|
for name in l:
|
||||||
f = open(test_case_dir + name, "wb")
|
f = open(test_case_dir + name, "wb")
|
||||||
f.write(test_case_file.read(name).replace("\r\n", "\n"))
|
try:
|
||||||
f.close()
|
f.write(test_case_file.read(name).replace("\r\n", "\n"))
|
||||||
|
except MemoryError:
|
||||||
|
return error_response(u"单个测试数据体积过大!")
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
l.sort()
|
l.sort()
|
||||||
|
|
||||||
file_info = {"test_case_number": len(l) / 2, "test_cases": {}}
|
file_info = {"test_case_number": len(l) / 2, "test_cases": {}}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
require(["jquery", "csrfToken", "bsAlert"], function ($, csrfTokenHeader, bsAlert) {
|
require(["jquery", "csrfToken", "bsAlert"], function ($, csrfTokenHeader, bsAlert) {
|
||||||
$("#sendApplication").click(function (){
|
$("#sendApplication").click(function (){
|
||||||
var message = $("#applyMessage").val();
|
var message;
|
||||||
console.log(message);
|
if ($("#applyMessage").length) {
|
||||||
|
message = $("#applyMessage").val();
|
||||||
|
if (!message)
|
||||||
|
bsAlert("提交失败,请填写申请信息!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var groupId = window.location.pathname.split("/")[2];
|
var groupId = window.location.pathname.split("/")[2];
|
||||||
console.log(groupId);
|
|
||||||
data = {group_id: groupId,message:message}
|
data = {group_id: groupId,message:message}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/group_join/",
|
url: "/api/group_join/",
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>当前没有合适的比赛</p>
|
<p>当前没有合适的比赛,你可以尝试到<a href="/groups/">小组列表</a>申请加入一些小组,以便参加小组内部的比赛</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
<div class="container main">
|
<div class="container main">
|
||||||
<ul class="nav nav-tabs nav-tabs-google">
|
<ul class="nav nav-tabs nav-tabs-google">
|
||||||
<li role="presentation" class="active">
|
<li role="presentation" class="active">
|
||||||
<a href="/group/{{ group.id }}/">详细信息</a></li>
|
<a href="/group/{{ group.id }}/">详细信息</a>
|
||||||
|
</li>
|
||||||
|
{% if group.join_group_setting %}
|
||||||
<li role="presentation"><a href="/group/{{ group.id }}/applications/">我的申请</a></li>
|
<li role="presentation"><a href="/group/{{ group.id }}/applications/">我的申请</a></li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
<h2 class="text-center">{{ group.name }}</h2>
|
<h2 class="text-center">{{ group.name }}</h2>
|
||||||
|
|
||||||
@@ -30,7 +33,11 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<button class="btn btn-primary" id="sendApplication">申请加入</button>
|
<button class="btn btn-primary" id="sendApplication">
|
||||||
|
{% if group.join_group_setting %}
|
||||||
|
申请
|
||||||
|
{% endif %}
|
||||||
|
加入</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
<a href="/submissions/">提交</a>
|
<a href="/submissions/">提交</a>
|
||||||
<a href="/contests/">比赛</a>
|
<a href="/contests/">比赛</a>
|
||||||
<a href="/groups/">小组</a>
|
<a href="/groups/">小组</a>
|
||||||
<a href="/about/">关于</a>
|
<a href="#">关于</a>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<li><a href="/submissions/">提交</a></li>
|
<li><a href="/submissions/">提交</a></li>
|
||||||
<li><a href="/contests/">比赛</a></li>
|
<li><a href="/contests/">比赛</a></li>
|
||||||
<li><a href="/groups/">小组</a></li>
|
<li><a href="/groups/">小组</a></li>
|
||||||
<li><a href="/about/">关于</a></li>
|
<li><a href="#">关于</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
@@ -97,4 +97,4 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- footer end -->
|
<!-- footer end -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user