重命名 sample -> samples

添加标签的逻辑变化
修改部分错误的测试用例
This commit is contained in:
virusdefender 2015-08-10 22:55:22 +08:00
parent 9d962a172f
commit cadb480573
5 changed files with 43 additions and 21 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('problem', '0002_remove_problemtag_description'),
]
operations = [
migrations.RenameField(
model_name='problem',
old_name='sample',
new_name='samples',
),
]

View File

@ -6,7 +6,6 @@ from account.models import User
class ProblemTag(models.Model):
name = models.CharField(max_length=30)
# description = models.CharField(max_length=50)
class Meta:
db_table = "problem_tag"
@ -18,7 +17,7 @@ class AbstractProblem(models.Model):
# 问题描述 HTML 格式
description = models.TextField()
# 样例输入 可能会存储 json 格式的数据
sample = models.TextField(blank=True)
samples = models.TextField(blank=True)
# 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置
test_case_id = models.CharField(max_length=40)
# 提示

View File

@ -14,7 +14,6 @@ class ProblemSampleSerializer(serializers.ListField):
class JSONField(serializers.Field):
def to_representation(self, value):
print value, type(value)
return json.loads(value)
@ -22,18 +21,18 @@ class CreateProblemSerializer(serializers.Serializer):
title = serializers.CharField(max_length=50)
description = serializers.CharField(max_length=10000)
# [{"input": "1 1", "output": "2"}]
sample = ProblemSampleSerializer()
samples = ProblemSampleSerializer()
test_case_id = serializers.CharField(max_length=40)
source = serializers.CharField(max_length=30, required=False, default=None)
time_limit = serializers.IntegerField()
memory_limit = serializers.IntegerField()
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.IntegerField())
tags = serializers.ListField(child=serializers.CharField(max_length=10))
hint = serializers.CharField(max_length=3000, required=False, default=None)
class ProblemSerializer(serializers.ModelSerializer):
sample = JSONField()
samples = JSONField()
class UserSerializer(serializers.ModelSerializer):
class Meta:
@ -56,7 +55,7 @@ class EditProblemSerializer(serializers.Serializer):
memory_limit = serializers.IntegerField()
difficulty = serializers.IntegerField()
tags = serializers.ListField(child=serializers.IntegerField())
sample = ProblemSampleSerializer()
samples = ProblemSampleSerializer()
hint = serializers.CharField(max_length=10000)
visible = serializers.BooleanField()

View File

@ -34,7 +34,7 @@ class ProblemAdminTest(APITestCase):
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",
@ -58,7 +58,7 @@ class ProblemAdminTest(APITestCase):
description="des1",
test_case_id="1",
source="source1",
sample=[{"input": "1 1", "output": "2"}],
samples=[{"input": "1 1", "output": "2"}],
time_limit=100,
memory_limit=1000,
difficulty=1,
@ -70,7 +70,7 @@ class ProblemAdminTest(APITestCase):
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",
@ -89,7 +89,7 @@ class ProblemAdminTest(APITestCase):
description="des1",
test_case_id="1",
source="source1",
sample=[{"input": "1 1", "output": "2"}],
samples=[{"input": "1 1", "output": "2"}],
time_limit=100,
memory_limit=1000,
difficulty=1,
@ -101,7 +101,7 @@ class ProblemAdminTest(APITestCase):
"description": "des1",
"test_case_id": "1",
"source": "source1",
"sample": [{"input": "1 1", "output": "2"}],
"samples": [{"input": "1 1", "output": "2"}],
"time_limit": "100",
"memory_limit": "1000",
"difficulty": "1",

View File

@ -34,6 +34,7 @@ class ProblemTagAdminAPIView(APIView):
return error_response(serializer)
def get(self, request):
return success_response(ProblemTagSerializer(ProblemTag.objects.all(), many=True).data)
keyword = request.GET.get("keyword", None)
if not keyword:
return error_response(u"参数错误")
@ -44,11 +45,11 @@ class ProblemTagAdminAPIView(APIView):
def problem_page(request, problem_id):
# try:
# problem = Problem.objects.get(id=problem_id)
# except Problem.DoesNotExist:
# return render(request, "utils/error.html", {"error": u"题目不存在"})
return render(request, "oj/problem/problem.html", {"problem": {}})
try:
problem = Problem.objects.get(id=problem_id)
except Problem.DoesNotExist:
return render(request, "utils/error.html", {"error": u"题目不存在"})
return render(request, "oj/problem/problem.html", {"problem": problem, "samples": json.loads(problem.samples)})
def problem_my_solutions_list_page(request, problem_id):
@ -75,15 +76,19 @@ class ProblemAdminAPIView(APIView):
description=data["description"],
test_case_id=data["test_case_id"],
source=data["source"],
sample=json.dumps(data["sample"]),
samples=json.dumps(data["samples"]),
time_limit=data["time_limit"],
memory_limit=data["memory_limit"],
difficulty=data["difficulty"],
created_by=request.user,
hint=data["hint"])
tags = ProblemTag.objects.filter(id__in=data["tags"])
problem.tags.add(*tags)
for tag in data["tags"]:
try:
tag = ProblemTag.objects.get(name=tag)
except ProblemTag.DoesNotExist:
tag = ProblemTag.objects.create(name=tag)
problem.tags.add(tag)
return success_response(ProblemSerializer(problem).data)
else:
return serializer_invalid_response(serializer)
@ -110,7 +115,7 @@ class ProblemAdminAPIView(APIView):
problem.time_limit = data["time_limit"]
problem.memory_limit = data["memory_limit"]
problem.difficulty = data["difficulty"]
problem.sample = json.dumps(data["sample"])
problem.samples = json.dumps(data["samples"])
problem.hint = data["hint"]
problem.visible = data["visible"]