diff --git a/contest/tests.py b/contest/tests.py index 4c160049a..a92e09ae5 100644 --- a/contest/tests.py +++ b/contest/tests.py @@ -79,7 +79,7 @@ def test_regular_user_validate_contest_password(self): 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) diff --git a/fps/parser.py b/fps/parser.py index 63d3559e5..5d4233116 100644 --- a/fps/parser.py +++ b/fps/parser.py @@ -17,9 +17,9 @@ def __init__(self, fps_path=None, string_data=None): self._ertree = ET.fromstring(string_data).getroot() else: raise ValueError("You must tell me the file path or directly give me the data for the file") - version = self._etree.attrib.get("version", "No Version") - if version not in ["1.1", "1.2"]: - raise ValueError("Unsupported version '" + version + "'") + self.version = self._etree.attrib.get("version", "No Version") + if self.version not in ["1.1", "1.2"]: + raise ValueError("Unsupported version '" + self.version + "'") @property def etree(self): @@ -52,7 +52,11 @@ def _parse_one_problem(self, node): if unit not in ["s", "ms"]: raise ValueError("Invalid time limit unit") problem["time_limit"]["unit"] = item.attrib.get("unit", "s") - value = int(item.text) + value = 0 + if self.version != "1.1": + value = float(item.text) + else: + value = int(item.text) if value <= 0: raise ValueError("Invalid time limit value") problem["time_limit"]["value"] = value diff --git a/problem/views/admin.py b/problem/views/admin.py index af66dc3db..1b0abf36d 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -1,7 +1,6 @@ import hashlib import json import os -import shutil import tempfile import zipfile from wsgiref.util import FileWrapper @@ -676,10 +675,10 @@ def post(self, request): 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/utils/constants.py b/utils/constants.py index ac0c97b62..749b20da7 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"