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 1/3] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=8F=8F=E8=BF=B0=E4=B8=8E=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E4=B8=A4=E4=B8=AA=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E6=94=B9=E5=85=B6=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=90=8E=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 b9a3181..82b99f6 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 b6b9faf..989c068 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 708d7f2..8838cce 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 f9677b1..73fc81a 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"] From a36dd1d267f73f2ef8134f69a99ef00e118ce44e Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 13 Aug 2015 18:03:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E7=95=8C=E9=9D=A2=E5=A2=9E=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=8F=8F=E8=BF=B0=E5=92=8C=E8=BE=93=E5=87=BA=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/migrations/0004_auto_20150813_1459.py | 26 +++++++++++++++++ .../src/js/app/admin/problem/add_problem.js | 28 ++++++++++++++----- template/admin/problem/add_problem.html | 14 ++++++++-- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 problem/migrations/0004_auto_20150813_1459.py diff --git a/problem/migrations/0004_auto_20150813_1459.py b/problem/migrations/0004_auto_20150813_1459.py new file mode 100644 index 0000000..387a87c --- /dev/null +++ b/problem/migrations/0004_auto_20150813_1459.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0003_auto_20150810_2233'), + ] + + operations = [ + migrations.AddField( + model_name='problem', + name='description_input', + field=models.CharField(default='hello', max_length=10000), + preserve_default=False, + ), + migrations.AddField( + model_name='problem', + name='description_output', + field=models.CharField(default='hello', max_length=10000), + preserve_default=False, + ), + ] diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js index d2eda56..ebb661e 100644 --- a/static/src/js/app/admin/problem/add_problem.js +++ b/static/src/js/app/admin/problem/add_problem.js @@ -53,10 +53,17 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito } } }, - source: { + input_description: { validators: { notEmpty: { - message: "请输入题目来源" + message: "请填写输入描述" + } + } + }, + output_description: { + validators: { + notEmpty: { + message: "请填写输出描述" } } } @@ -72,10 +79,6 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito bs_alert("题目描述不能为空!"); return; } - if (vm.hint == '') { - bs_alert("提示不能为空!"); - return; - } var ajaxData = { title: vm.title, description: vm.description, @@ -86,6 +89,8 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito hint: vm.hint, source: vm.source, tags: $("#tags").tagEditor("getTags")[0].tags, + input_description: vm.input_description, + output_description: vm.output_description, difficulty: vm.difficulty }; if (vm.samples.length == 0) { @@ -93,6 +98,13 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito return; } + for(var i = 0; i < vm.samples.length; i++){ + if (vm.samples[i].input == "" || vm.samples[i].output == ""){ + bs_alert("样例输入与样例输出不能为空!"); + return; + } + } + if (tags.length == 0) { bs_alert("请至少添加一个标签,这将有利于用户发现你的题目!"); return; @@ -147,12 +159,14 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito description: "", cpu: 1000, memory: 256, - samples: [], + samples: [{input: "", output: "", "visible": true}], hint: "", visible: true, difficulty: 0, tags: [], tag: "", + input_description: "", + output_description: "", test_case_id: "", testCaseList: [], uploadSuccess: false, diff --git a/template/admin/problem/add_problem.html b/template/admin/problem/add_problem.html index 0b952c9..a6cf14c 100644 --- a/template/admin/problem/add_problem.html +++ b/template/admin/problem/add_problem.html @@ -3,12 +3,12 @@
- +
- + 请填写题目描述
@@ -38,6 +38,16 @@
+
+
+ +
+
+
+ +

添加 From 692a0398015194305710f9383d463f68b5f76c71 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 13 Aug 2015 18:08:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8E=E7=AB=AFproblem?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=9A=84=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/migrations/0005_auto_20150813_1807.py | 24 +++++++++++++++++++ problem/models.py | 4 ++-- problem/serizalizers.py | 8 +++---- problem/tests.py | 12 +++++----- problem/views.py | 8 +++---- 5 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 problem/migrations/0005_auto_20150813_1807.py diff --git a/problem/migrations/0005_auto_20150813_1807.py b/problem/migrations/0005_auto_20150813_1807.py new file mode 100644 index 0000000..7d50f75 --- /dev/null +++ b/problem/migrations/0005_auto_20150813_1807.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0004_auto_20150813_1459'), + ] + + operations = [ + migrations.RenameField( + model_name='problem', + old_name='description_input', + new_name='input_description', + ), + migrations.RenameField( + model_name='problem', + old_name='description_output', + new_name='output_description', + ), + ] diff --git a/problem/models.py b/problem/models.py index 82b99f6..3be3783 100644 --- a/problem/models.py +++ b/problem/models.py @@ -17,9 +17,9 @@ class AbstractProblem(models.Model): # 问题描述 HTML 格式 description = models.TextField() # 输入描述 - description_input = models.CharField(max_length=10000) + input_description = models.CharField(max_length=10000) # 输出描述 - description_output = models.CharField(max_length=10000) + output_description = models.CharField(max_length=10000) # 样例输入 可能会存储 json 格式的数据 samples = models.TextField(blank=True) # 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置 diff --git a/problem/serizalizers.py b/problem/serizalizers.py index 989c068..d7a1856 100644 --- a/problem/serizalizers.py +++ b/problem/serizalizers.py @@ -20,8 +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_description = serializers.CharField(max_length=10000) + output_description = serializers.CharField(max_length=10000) # [{"input": "1 1", "output": "2"}] samples = ProblemSampleSerializer() test_case_id = serializers.CharField(max_length=40) @@ -51,8 +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) + input_description = serializers.CharField(max_length=10000) + output_description = 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 8838cce..1823655 100644 --- a/problem/tests.py +++ b/problem/tests.py @@ -19,8 +19,8 @@ class ProblemAdminTest(APITestCase): data = {"id": problem_id, "title": "title0", "description": "description0", - "description_input": "description_input0", - "description_output": "description_output0", + "input_description": "input_description0", + "output_description": "output_description0", "test_case_id": "1", "source": "source1", "samples": [{"input": "1 1", "output": "2"}], @@ -43,8 +43,8 @@ class ProblemAdminTest(APITestCase): ProblemTag.objects.create(name="tag2") self.problem = Problem.objects.create(title="title1", description="description1", - description_input="description_input1", - description_output="description_output1", + input_description="input1_description", + output_description="output1_description", test_case_id="1", source="source1", samples=[{"input": "1 1", "output": "2"}], @@ -63,8 +63,8 @@ class ProblemAdminTest(APITestCase): def test_release_problem_successfully(self): data = {"title": "title2", "description": "description2", - "description_input": "description_input2", - "description_output": "description_output2", + "input_description": "input_description2", + "output_description": "output_description2", "test_case_id": "1", "source": "source1", "samples": [{"input": "1 1", "output": "2"}], diff --git a/problem/views.py b/problem/views.py index 73fc81a..0f618cd 100644 --- a/problem/views.py +++ b/problem/views.py @@ -74,8 +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"], + input_description=data["input_description"], + output_description=data["output_description"], test_case_id=data["test_case_id"], source=data["source"], samples=json.dumps(data["samples"]), @@ -112,8 +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.input_description = data["input_description"] + problem.output_description = data["output_description"] problem.test_case_id = data["test_case_id"] problem.source = data["source"] problem.time_limit = data["time_limit"]