mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
submission exists api
This commit is contained in:
parent
2b4fb4f368
commit
45953b8f80
@ -17,7 +17,7 @@ install:
|
|||||||
script:
|
script:
|
||||||
- docker ps -a
|
- docker ps -a
|
||||||
- flake8 .
|
- flake8 .
|
||||||
- coverage run --include="$PWD/*" manage.py test
|
- coverage run --source='.' manage.py test
|
||||||
- coverage report
|
- coverage report
|
||||||
notifications:
|
notifications:
|
||||||
slack: onlinejudgeteam:BzBz8UFgmS5crpiblof17K2W
|
slack: onlinejudgeteam:BzBz8UFgmS5crpiblof17K2W
|
||||||
|
@ -94,11 +94,11 @@ def check_contest_permission(check_type="details"):
|
|||||||
(self.contest.id not in request.session["accessible_contests"]):
|
(self.contest.id not in request.session["accessible_contests"]):
|
||||||
return self.error("Password is required.")
|
return self.error("Password is required.")
|
||||||
|
|
||||||
# regular use get contest problems, ranks etc. before contest started
|
# regular user get contest problems, ranks etc. before contest started
|
||||||
if self.contest.status == ContestStatus.CONTEST_NOT_START and check_type != "details":
|
if self.contest.status == ContestStatus.CONTEST_NOT_START and check_type != "details":
|
||||||
return self.error("Contest has not started yet.")
|
return self.error("Contest has not started yet.")
|
||||||
|
|
||||||
# check is user have permission to get ranks, submissions OI Contest
|
# check does user have permission to get ranks, submissions OI Contest
|
||||||
if self.contest.status == ContestStatus.CONTEST_UNDERWAY and self.contest.rule_type == ContestRuleType.OI:
|
if self.contest.status == ContestStatus.CONTEST_UNDERWAY and self.contest.rule_type == ContestRuleType.OI:
|
||||||
if not self.contest.real_time_rank and (check_type == "ranks" or check_type == "submissions"):
|
if not self.contest.real_time_rank and (check_type == "ranks" or check_type == "submissions"):
|
||||||
return self.error(f"No permission to get {check_type}")
|
return self.error(f"No permission to get {check_type}")
|
||||||
|
@ -21,7 +21,7 @@ class UserAdminAPI(APIView):
|
|||||||
data = request.data["users"]
|
data = request.data["users"]
|
||||||
omitted_count = created_count = get_count = 0
|
omitted_count = created_count = get_count = 0
|
||||||
for user_data in data:
|
for user_data in data:
|
||||||
if len(user_data) != 3:
|
if len(user_data) != 3 or len(user_data[0]) > 32:
|
||||||
omitted_count += 1
|
omitted_count += 1
|
||||||
continue
|
continue
|
||||||
user, created = User.objects.get_or_create(username=user_data[0])
|
user, created = User.objects.get_or_create(username=user_data[0])
|
||||||
@ -167,7 +167,7 @@ class GenerateUserAPI(APIView):
|
|||||||
number_max_length = max(len(str(data["number_from"])), len(str(data["number_to"])))
|
number_max_length = max(len(str(data["number_from"])), len(str(data["number_to"])))
|
||||||
if number_max_length + len(data["prefix"]) + len(data["suffix"]) > 32:
|
if number_max_length + len(data["prefix"]) + len(data["suffix"]) > 32:
|
||||||
return self.error("Username should not more than 32 characters")
|
return self.error("Username should not more than 32 characters")
|
||||||
if data["number_from"] >= data["number_to"]:
|
if data["number_from"] > data["number_to"]:
|
||||||
return self.error("Start number must be lower than end number")
|
return self.error("Start number must be lower than end number")
|
||||||
|
|
||||||
password_length = data.get("password_length", 8)
|
password_length = data.get("password_length", 8)
|
||||||
|
@ -21,7 +21,7 @@ print("running flake8...")
|
|||||||
if os.system("flake8 --statistics ."):
|
if os.system("flake8 --statistics ."):
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
ret = os.system("coverage run ./manage.py test {module} --settings={setting}".format(module=test_module, setting=setting))
|
ret = os.system("coverage run --source='.' ./manage.py test {module} --settings={setting}".format(module=test_module, setting=setting))
|
||||||
|
|
||||||
if not ret and is_coverage:
|
if not ret and is_coverage:
|
||||||
os.system("coverage html && open htmlcov/index.html")
|
os.system("coverage html && open htmlcov/index.html")
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from ..views.oj import SubmissionAPI, SubmissionListAPI, ContestSubmissionListAPI
|
from ..views.oj import SubmissionAPI, SubmissionListAPI, ContestSubmissionListAPI, SubmissionExistsAPI
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r"^submission/?$", SubmissionAPI.as_view(), name="submission_api"),
|
url(r"^submission/?$", SubmissionAPI.as_view(), name="submission_api"),
|
||||||
url(r"^submissions/?$", SubmissionListAPI.as_view(), name="submission_list_api"),
|
url(r"^submissions/?$", SubmissionListAPI.as_view(), name="submission_list_api"),
|
||||||
|
url(r"^submission_exists/?$", SubmissionExistsAPI.as_view(), name="submission_exists"),
|
||||||
url(r"^contest_submissions/?$", ContestSubmissionListAPI.as_view(), name="contest_submission_list_api"),
|
url(r"^contest_submissions/?$", ContestSubmissionListAPI.as_view(), name="contest_submission_list_api"),
|
||||||
]
|
]
|
||||||
|
@ -200,3 +200,12 @@ class ContestSubmissionListAPI(APIView):
|
|||||||
data = self.paginate_data(request, submissions)
|
data = self.paginate_data(request, submissions)
|
||||||
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
|
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
|
||||||
return self.success(data)
|
return self.success(data)
|
||||||
|
|
||||||
|
|
||||||
|
class SubmissionExistsAPI(APIView):
|
||||||
|
def get(self, request):
|
||||||
|
if not request.GET.get("problem_id"):
|
||||||
|
return self.error("Parameter error, problem_id is required")
|
||||||
|
return self.success(request.user.is_authenticated and
|
||||||
|
Submission.objects.filter(problem_id=request.GET["problem_id"],
|
||||||
|
user_id=request.user.id).exists())
|
||||||
|
Loading…
Reference in New Issue
Block a user