From a4a66d227166d7969c349c1dab7dba42eee97c9b Mon Sep 17 00:00:00 2001 From: helsonxiao Date: Sun, 29 Nov 2020 14:00:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(test):=20=E4=BF=AE=E5=A4=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contest/tests.py b/contest/tests.py index 4c160049..a92e09ae 100644 --- a/contest/tests.py +++ b/contest/tests.py @@ -79,7 +79,7 @@ class ContestAPITest(APITestCase): self.create_user("test", "test123") url = self.reverse("contest_password_api") resp = self.client.post(url, {"contest_id": self.contest.id, "password": "error_password"}) - self.assertDictEqual(resp.data, {"error": "error", "data": "Wrong password"}) + self.assertDictEqual(resp.data, {"error": "error", "data": "Wrong password or password expired"}) resp = self.client.post(url, {"contest_id": self.contest.id, "password": DEFAULT_CONTEST_DATA["password"]}) self.assertSuccess(resp) From 515f422a2d056bbe879b0b6135548d694f28084c Mon Sep 17 00:00:00 2001 From: helsonxiao Date: Sun, 29 Nov 2020 14:01:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(problem=20tag):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/views/oj.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/problem/views/oj.py b/problem/views/oj.py index b091ff31..3d3c4435 100644 --- a/problem/views/oj.py +++ b/problem/views/oj.py @@ -9,7 +9,11 @@ from contest.models import ContestRuleType class ProblemTagAPI(APIView): def get(self, request): - tags = ProblemTag.objects.annotate(problem_count=Count("problem")).filter(problem_count__gt=0) + qs = ProblemTag.objects + keyword = request.GET.get('keyword') + if keyword: + qs = ProblemTag.objects.filter(name__icontains=keyword) + tags = qs.annotate(problem_count=Count("problem")).filter(problem_count__gt=0) return self.success(TagSerializer(tags, many=True).data) From 0566b2856e2316e4a99adb54e2c65bd8331883fb Mon Sep 17 00:00:00 2001 From: helsonxiao Date: Sun, 29 Nov 2020 14:07:18 +0800 Subject: [PATCH 3/3] fix(style): code style --- problem/views/admin.py | 6 +++--- problem/views/oj.py | 2 +- utils/constants.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/problem/views/admin.py b/problem/views/admin.py index af66dc3d..280e4fa1 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -1,7 +1,7 @@ import hashlib import json import os -import shutil +# import shutil import tempfile import zipfile from wsgiref.util import FileWrapper @@ -676,10 +676,10 @@ class FPSProblemImport(CSRFExemptAPIView): with tempfile.NamedTemporaryFile("wb") as tf: for chunk in file.chunks(4096): tf.file.write(chunk) - + tf.file.flush() os.fsync(tf.file) - + problems = FPSParser(tf.name).parse() else: return self.error("Parse upload file error") diff --git a/problem/views/oj.py b/problem/views/oj.py index 3d3c4435..534fa605 100644 --- a/problem/views/oj.py +++ b/problem/views/oj.py @@ -10,7 +10,7 @@ from contest.models import ContestRuleType class ProblemTagAPI(APIView): def get(self, request): qs = ProblemTag.objects - keyword = request.GET.get('keyword') + keyword = request.GET.get("keyword") if keyword: qs = ProblemTag.objects.filter(name__icontains=keyword) tags = qs.annotate(problem_count=Count("problem")).filter(problem_count__gt=0) diff --git a/utils/constants.py b/utils/constants.py index ac0c97b6..749b20da 100644 --- a/utils/constants.py +++ b/utils/constants.py @@ -33,4 +33,4 @@ class Difficulty(Choices): HIGH = "High" -CONTEST_PASSWORD_SESSION_KEY = "contest_password" \ No newline at end of file +CONTEST_PASSWORD_SESSION_KEY = "contest_password"