mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
增加通过api获取题目的逻辑
This commit is contained in:
parent
863e511d32
commit
823c6be0e1
@ -20,7 +20,7 @@ from group.views import (GroupAdminAPIView, GroupMemberAdminAPIView,
|
|||||||
|
|
||||||
from admin.views import AdminTemplateView
|
from admin.views import AdminTemplateView
|
||||||
|
|
||||||
from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, ProblemAdminAPIView
|
from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, ProblemAdminAPIView, OpenAPIProblemAPI
|
||||||
from submission.views import (SubmissionAPIView, SubmissionAdminAPIView, ContestSubmissionAPIView,
|
from submission.views import (SubmissionAPIView, SubmissionAdminAPIView, ContestSubmissionAPIView,
|
||||||
SubmissionShareAPIView, SubmissionRejudgeAdminAPIView)
|
SubmissionShareAPIView, SubmissionRejudgeAdminAPIView)
|
||||||
from judge_dispatcher.views import AdminJudgeServerAPIView
|
from judge_dispatcher.views import AdminJudgeServerAPIView
|
||||||
@ -92,6 +92,8 @@ urlpatterns = [
|
|||||||
url(r'^contests/$', "contest.views.contest_list_page", name="contest_list_page"),
|
url(r'^contests/$', "contest.views.contest_list_page", name="contest_list_page"),
|
||||||
url(r'^contests/(?P<page>\d+)/$', "contest.views.contest_list_page", name="contest_list_page"),
|
url(r'^contests/(?P<page>\d+)/$', "contest.views.contest_list_page", name="contest_list_page"),
|
||||||
|
|
||||||
|
url(r'^api/open/problem/$', OpenAPIProblemAPI.as_view(), name="openapi_problem_api"),
|
||||||
|
|
||||||
url(r'^problem/(?P<problem_id>\d+)/$', "problem.views.problem_page", name="problem_page"),
|
url(r'^problem/(?P<problem_id>\d+)/$', "problem.views.problem_page", name="problem_page"),
|
||||||
url(r'^problems/$', "problem.views.problem_list_page", name="problem_list_page"),
|
url(r'^problems/$', "problem.views.problem_list_page", name="problem_list_page"),
|
||||||
url(r'^problems/(?P<page>\d+)/$', "problem.views.problem_list_page", name="problem_list_page"),
|
url(r'^problems/(?P<page>\d+)/$', "problem.views.problem_list_page", name="problem_list_page"),
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class ProblemTagSerializer(serializers.ModelSerializer):
|
|||||||
model = ProblemTag
|
model = ProblemTag
|
||||||
|
|
||||||
|
|
||||||
class ProblemSerializer(serializers.ModelSerializer):
|
class BaseProblemSerializer(serializers.ModelSerializer):
|
||||||
samples = JSONField()
|
samples = JSONField()
|
||||||
tags = ProblemTagSerializer(many=True)
|
tags = ProblemTagSerializer(many=True)
|
||||||
|
|
||||||
@ -50,10 +50,19 @@ class ProblemSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
created_by = UserSerializer()
|
created_by = UserSerializer()
|
||||||
|
|
||||||
|
|
||||||
|
class ProblemSerializer(BaseProblemSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Problem
|
model = Problem
|
||||||
|
|
||||||
|
|
||||||
|
class OpenAPIProblemSerializer(BaseProblemSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Problem
|
||||||
|
exclude = ["visible", "test_case_id"]
|
||||||
|
|
||||||
|
|
||||||
class EditProblemSerializer(serializers.Serializer):
|
class EditProblemSerializer(serializers.Serializer):
|
||||||
id = serializers.IntegerField()
|
id = serializers.IntegerField()
|
||||||
title = serializers.CharField(max_length=50)
|
title = serializers.CharField(max_length=50)
|
||||||
|
|||||||
@ -13,12 +13,12 @@ from django.utils.timezone import now
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from account.models import SUPER_ADMIN
|
from account.models import SUPER_ADMIN, User
|
||||||
from account.decorators import super_admin_required
|
from account.decorators import super_admin_required
|
||||||
from utils.shortcuts import (serializer_invalid_response, error_response,
|
from utils.shortcuts import (serializer_invalid_response, error_response,
|
||||||
success_response, paginate, rand_str, error_page)
|
success_response, paginate, rand_str, error_page)
|
||||||
from .serizalizers import (CreateProblemSerializer, EditProblemSerializer, ProblemSerializer,
|
from .serizalizers import (CreateProblemSerializer, EditProblemSerializer, ProblemSerializer,
|
||||||
ProblemTagSerializer)
|
ProblemTagSerializer, OpenAPIProblemSerializer)
|
||||||
from .models import Problem, ProblemTag
|
from .models import Problem, ProblemTag
|
||||||
from .decorators import check_user_problem_permission
|
from .decorators import check_user_problem_permission
|
||||||
|
|
||||||
@ -36,6 +36,26 @@ def problem_page(request, problem_id):
|
|||||||
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
|
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
|
||||||
|
|
||||||
|
|
||||||
|
class OpenAPIProblemAPI(APIView):
|
||||||
|
def get(sell, request):
|
||||||
|
"""
|
||||||
|
openapi 获取题目内容
|
||||||
|
"""
|
||||||
|
problem_id = request.GET.get("problem_id", None)
|
||||||
|
appkey = request.GET.get("appkey", None)
|
||||||
|
if not (problem_id and appkey):
|
||||||
|
return error_response(u"参数错误")
|
||||||
|
try:
|
||||||
|
User.objects.get(openapi_appkey=appkey)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return error_response(u"appkey无效")
|
||||||
|
try:
|
||||||
|
problem = Problem.objects.get(id=problem_id, visible=True)
|
||||||
|
except Problem.DoesNotExist:
|
||||||
|
return error_page(request, u"题目不存在")
|
||||||
|
return success_response(OpenAPIProblemSerializer(problem).data)
|
||||||
|
|
||||||
|
|
||||||
class ProblemTagAdminAPIView(APIView):
|
class ProblemTagAdminAPIView(APIView):
|
||||||
"""
|
"""
|
||||||
获取所有标签的列表
|
获取所有标签的列表
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user