reformat code.

This commit is contained in:
zemal 2017-07-18 11:25:08 +08:00
parent ee49d0a815
commit 8b85f86124
6 changed files with 11 additions and 17 deletions

View File

@ -4,7 +4,7 @@ from utils.api import JSONResponse
from .models import ProblemPermission
from contest.models import Contest, ContestType, ContestStatus
from contest.models import Contest, ContestType
class BasePermissionDecorator(object):
@ -67,10 +67,10 @@ def check_contest_permission(func):
self = args[0]
request = args[1]
user = request.user
if kwargs.get('contest_id'):
contest_id = kwargs.pop('contest_id')
if kwargs.get("contest_id"):
contest_id = kwargs.pop("contest_id")
else:
contest_id = request.GET.get('contest_id')
contest_id = request.GET.get("contest_id")
if not contest_id:
return self.error("Parameter contest_id not exist.")

View File

@ -2,8 +2,6 @@ from utils.api import DateTimeTZField, UsernameSerializer, serializers
from .models import Contest, ContestAnnouncement, ContestRuleType
from problem.serializers import ContestProblemSerializer
class CreateConetestSeriaizer(serializers.Serializer):
title = serializers.CharField(max_length=128)
@ -43,7 +41,7 @@ class ContestAdminSerializer(serializers.ModelSerializer):
class ContestSerializer(ContestAdminSerializer):
class Meta:
model = Contest
exclude = ('password', 'visible')
exclude = ("password", "visible")
class ContestAnnouncementSerializer(serializers.ModelSerializer):

View File

@ -99,4 +99,4 @@ class ContestProblemSerializer(serializers.ModelSerializer):
created_by = UsernameSerializer()
class Meta:
model = ContestProblem
model = ContestProblem

View File

@ -208,18 +208,17 @@ class ContestProblemTest(APITestCase):
def test_get_one_contest_problem(self):
contest_id = self.contest.data["data"]["id"]
problem_id = self.problem.data["data"]["_id"]
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url,contest_id, problem_id))
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url, contest_id, problem_id))
self.assertSuccess(resp)
def test_regular_user_get_contest_problem(self):
self.create_user("test", "test123")
contest_id = self.contest.data["data"]["id"]
problem_id = self.problem.data["data"]["_id"]
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url,contest_id, problem_id))
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url, contest_id, problem_id))
self.assertFailed(resp)
url = self.reverse("contest_password_api")
self.client.post(url, {"contest_id": contest_id, "password": DEFAULT_CONTEST_DATA["password"]})
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url,contest_id, problem_id))
resp = self.client.get("{}?contest_id={}&problem_id={}".format(self.url, contest_id, problem_id))
self.assertSuccess(resp)

View File

@ -1,6 +1,6 @@
from django.db.models import Q
from utils.api import APIView
from account.decorators import login_required, check_contest_permission
from account.decorators import check_contest_permission
from ..models import ProblemTag, Problem, ContestProblem
from ..serializers import ProblemSerializer, TagSerializer
from ..serializers import ContestProblemSerializer

View File

@ -1,13 +1,12 @@
from django_redis import get_redis_connection
from account.decorators import login_required
from account.models import AdminType, User
from problem.models import Problem, ProblemRuleType
from submission.tasks import judge_task
# from judge.dispatcher import JudgeDispatcher
from utils.api import APIView, validate_serializer
from utils.throttling import TokenBucket, BucketController
from ..models import Submission, JudgeStatus
from ..models import Submission
from ..serializers import CreateSubmissionSerializer, SubmissionModelSerializer
from ..serializers import SubmissionSafeSerializer, SubmissionListSerializer
@ -87,5 +86,3 @@ class SubmissionListAPI(APIView):
data = self.paginate_data(request, subs)
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
return self.success(data)