mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
Merge pull request #340 from helsonxiao/master
feat: problem tag 支持模糊搜索
This commit is contained in:
commit
9119c01159
@ -79,7 +79,7 @@ class ContestAPITest(APITestCase):
|
|||||||
self.create_user("test", "test123")
|
self.create_user("test", "test123")
|
||||||
url = self.reverse("contest_password_api")
|
url = self.reverse("contest_password_api")
|
||||||
resp = self.client.post(url, {"contest_id": self.contest.id, "password": "error_password"})
|
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"]})
|
resp = self.client.post(url, {"contest_id": self.contest.id, "password": DEFAULT_CONTEST_DATA["password"]})
|
||||||
self.assertSuccess(resp)
|
self.assertSuccess(resp)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
# import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import zipfile
|
import zipfile
|
||||||
from wsgiref.util import FileWrapper
|
from wsgiref.util import FileWrapper
|
||||||
@ -676,10 +676,10 @@ class FPSProblemImport(CSRFExemptAPIView):
|
|||||||
with tempfile.NamedTemporaryFile("wb") as tf:
|
with tempfile.NamedTemporaryFile("wb") as tf:
|
||||||
for chunk in file.chunks(4096):
|
for chunk in file.chunks(4096):
|
||||||
tf.file.write(chunk)
|
tf.file.write(chunk)
|
||||||
|
|
||||||
tf.file.flush()
|
tf.file.flush()
|
||||||
os.fsync(tf.file)
|
os.fsync(tf.file)
|
||||||
|
|
||||||
problems = FPSParser(tf.name).parse()
|
problems = FPSParser(tf.name).parse()
|
||||||
else:
|
else:
|
||||||
return self.error("Parse upload file error")
|
return self.error("Parse upload file error")
|
||||||
|
|||||||
@ -9,7 +9,11 @@ from contest.models import ContestRuleType
|
|||||||
|
|
||||||
class ProblemTagAPI(APIView):
|
class ProblemTagAPI(APIView):
|
||||||
def get(self, request):
|
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)
|
return self.success(TagSerializer(tags, many=True).data)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,4 +33,4 @@ class Difficulty(Choices):
|
|||||||
HIGH = "High"
|
HIGH = "High"
|
||||||
|
|
||||||
|
|
||||||
CONTEST_PASSWORD_SESSION_KEY = "contest_password"
|
CONTEST_PASSWORD_SESSION_KEY = "contest_password"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user