[后端]修改GET比赛分页API,对普通管理员仅返回自己创建的比赛,但在多用户创建过比赛是(只要当前用户获取其他用户的比赛是就会产生错误,这是原来就有的BUG),还未写测试

This commit is contained in:
esp
2015-08-23 17:34:27 +08:00
parent fe043007fa
commit cca4bb3852
4 changed files with 16 additions and 1 deletions

View File

@@ -126,7 +126,10 @@ class ContestAdminAPIView(APIView):
---
response_serializer: ContestSerializer
"""
contest = Contest.objects.all().order_by("-last_updated_time")
if request.user.admin_type == SUPER_ADMIN:
contest = Contest.objects.all().order_by("-last_update_time")
else:
contest = Contest.objects.filter(created_by=request.user).order_by("-last_updated_time")
visible = request.GET.get("visible", None)
if visible:
contest = contest.filter(visible=(visible == "true"))
@@ -219,5 +222,12 @@ class ContestProblemAdminAPIView(APIView):
if keyword:
contest_problem = contest_problem.filter(Q(title__contains=keyword) |
Q(description__contains=keyword))
contest_id = request.GET.get("contest_id", None)
if contest_id:
try:
contest = Contest.objects.get(id=contest_id,created_by=request.user)
except Contest.DoesNotExist:
return error_response(u"非法的比赛ID")
contest_problem = contest_problem.filter(contest=contest).order_by("sort_index")
return paginate(request, contest_problem, ContestProblemSerializer)

View File

@@ -0,0 +1,5 @@
.group-tag {
padding-left: 5px; color: #46799b; background: #e0eaf1; white-space: nowrap;
overflow: hidden; cursor: pointer; border-radius: 2px 0 0 2px;
float: left; padding: 0 4px;box-sizing: border-box;list-style-type: none; margin: 5px;
}

View File