修复创建编辑问题的时候提示不能为空的问题

This commit is contained in:
virusdefender 2015-08-17 16:32:12 +08:00
parent b4f45a619f
commit 3385ddce18
3 changed files with 8 additions and 6 deletions

View File

@ -14,7 +14,8 @@ from group.views import (GroupAdminAPIView, GroupMemberAdminAPIView,
from admin.views import AdminTemplateView
from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, ProblemAdminAPIView
from submission.views import SubmissionAPIView
from submission.views import SubmissionAPIView, SubmissionAdminAPIView
urlpatterns = [
url(r'^install/$', "install.views.install"),
@ -57,5 +58,6 @@ urlpatterns = [
url(r'^api/admin/join_group_request/$', JoinGroupRequestAdminAPIView.as_view(),
name="join_group_request_admin_api"),
url(r'^api/submission/$', SubmissionAPIView.as_view(), name="submission_api"),
url(r'^api/admin/submission/$', SubmissionAdminAPIView.as_view(), name="submission_admin_api_view"),
]

View File

@ -30,7 +30,7 @@ class CreateProblemSerializer(serializers.Serializer):
memory_limit = serializers.IntegerField()
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.CharField(max_length=10))
hint = serializers.CharField(max_length=3000, required=False, default=None)
hint = serializers.CharField(max_length=3000, allow_blank=True)
class ProblemTagSerializer(serializers.ModelSerializer):
@ -66,7 +66,7 @@ class EditProblemSerializer(serializers.Serializer):
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.CharField(max_length=20))
samples = ProblemSampleSerializer()
hint = serializers.CharField(max_length=10000)
hint = serializers.CharField(max_length=3000, allow_blank=True)
visible = serializers.BooleanField()

View File

@ -22,7 +22,7 @@ from .models import Problem, ProblemTag
def problem_page(request, problem_id):
try:
problem = Problem.objects.get(id=problem_id)
problem = Problem.objects.get(id=problem_id, visible=True)
except Problem.DoesNotExist:
return error_page(request, u"题目不存在")
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
@ -122,7 +122,7 @@ class ProblemAdminAPIView(APIView):
return success_response(ProblemSerializer(problem).data)
except Problem.DoesNotExist:
return error_response(u"题目不存在")
problem = Problem.objects.all().order_by("-last_update_time")
problem = Problem.objects.all().order_by("-create_time")
visible = request.GET.get("visible", None)
if visible:
problem = problem.filter(visible=(visible == "true"))
@ -217,7 +217,7 @@ class TestCaseUploadAPIView(APIView):
def problem_list_page(request, page=1):
# 正常情况
problems = Problem.objects.all()
problems = Problem.objects.filter(visible=True)
# 搜索的情况
keyword = request.GET.get("keyword", None)