From d8d91b7ecd61d4525b02f75e29d02fef895e7039 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 13 Aug 2015 15:15:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=A2=9E=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=8F=8F=E8=BF=B0=E4=B8=8E=E8=BE=93=E5=87=BA=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E4=B8=A4=E4=B8=AA=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=B6=E7=9B=B8=E5=85=B3=E7=9A=84=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/models.py | 4 ++++ problem/serizalizers.py | 4 ++++ problem/tests.py | 16 +++++++++++----- problem/views.py | 4 ++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/problem/models.py b/problem/models.py index b9a31813..82b99f6b 100644 --- a/problem/models.py +++ b/problem/models.py @@ -16,6 +16,10 @@ class AbstractProblem(models.Model): title = models.CharField(max_length=50) # 问题描述 HTML 格式 description = models.TextField() + # 输入描述 + description_input = models.CharField(max_length=10000) + # 输出描述 + description_output = models.CharField(max_length=10000) # 样例输入 可能会存储 json 格式的数据 samples = models.TextField(blank=True) # 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置 diff --git a/problem/serizalizers.py b/problem/serizalizers.py index b6b9faf8..989c068a 100644 --- a/problem/serizalizers.py +++ b/problem/serizalizers.py @@ -20,6 +20,8 @@ class JSONField(serializers.Field): class CreateProblemSerializer(serializers.Serializer): title = serializers.CharField(max_length=50) description = serializers.CharField(max_length=10000) + description_input = serializers.CharField(max_length=10000) + description_output = serializers.CharField(max_length=10000) # [{"input": "1 1", "output": "2"}] samples = ProblemSampleSerializer() test_case_id = serializers.CharField(max_length=40) @@ -49,6 +51,8 @@ class EditProblemSerializer(serializers.Serializer): id = serializers.IntegerField() title = serializers.CharField(max_length=50) description = serializers.CharField(max_length=10000) + description_input = serializers.CharField(max_length=10000) + description_output = serializers.CharField(max_length=10000) test_case_id = serializers.CharField(max_length=40) source = serializers.CharField(max_length=30) time_limit = serializers.IntegerField() diff --git a/problem/tests.py b/problem/tests.py index 708d7f24..8838cce8 100644 --- a/problem/tests.py +++ b/problem/tests.py @@ -17,8 +17,10 @@ class ProblemPageTest(TestCase): class ProblemAdminTest(APITestCase): def _create_data(self, problem_id, visible, tags): data = {"id": problem_id, - "title": "title1", - "description": "des1", + "title": "title0", + "description": "description0", + "description_input": "description_input0", + "description_output": "description_output0", "test_case_id": "1", "source": "source1", "samples": [{"input": "1 1", "output": "2"}], @@ -40,7 +42,9 @@ class ProblemAdminTest(APITestCase): ProblemTag.objects.create(name="tag1") ProblemTag.objects.create(name="tag2") self.problem = Problem.objects.create(title="title1", - description="des1", + description="description1", + description_input="description_input1", + description_output="description_output1", test_case_id="1", source="source1", samples=[{"input": "1 1", "output": "2"}], @@ -57,8 +61,10 @@ class ProblemAdminTest(APITestCase): self.assertEqual(response.data["code"], 1) def test_release_problem_successfully(self): - data = {"title": "title1", - "description": "des1", + data = {"title": "title2", + "description": "description2", + "description_input": "description_input2", + "description_output": "description_output2", "test_case_id": "1", "source": "source1", "samples": [{"input": "1 1", "output": "2"}], diff --git a/problem/views.py b/problem/views.py index f9677b1c..73fc81ab 100644 --- a/problem/views.py +++ b/problem/views.py @@ -74,6 +74,8 @@ class ProblemAdminAPIView(APIView): data = serializer.data problem = Problem.objects.create(title=data["title"], description=data["description"], + description_input=data["description_input"], + description_output=data["description_output"], test_case_id=data["test_case_id"], source=data["source"], samples=json.dumps(data["samples"]), @@ -110,6 +112,8 @@ class ProblemAdminAPIView(APIView): problem.title = data["title"] problem.description = data["description"] + problem.description_input = data["description_input"] + problem.description_output = data["description_output"] problem.test_case_id = data["test_case_id"] problem.source = data["source"] problem.time_limit = data["time_limit"]