From d8e514911ab0c2975be17ab45c24b33cfffee120 Mon Sep 17 00:00:00 2001 From: Phuoc Dinh Le <47278241+cuom1999@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:32:15 -0500 Subject: [PATCH 1/3] Fix VNese bugs when after trimming --- judge/views/submission.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/judge/views/submission.py b/judge/views/submission.py index 5793ef1..4e278ac 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -141,16 +141,16 @@ def read_head_archive(archive, file): with archive.open(file) as f: return f.read(settings.TESTCASE_VISIBLE_LENGTH + 3) - def get_visible_content(data): data = data or b'' data = data.replace(b'\r\n', b'\r').replace(b'\r', b'\n') + + data = data.decode('utf-8') + if (len(data) > settings.TESTCASE_VISIBLE_LENGTH): data = data[:settings.TESTCASE_VISIBLE_LENGTH] - data += b'.' * 3 - elif not data.endswith(b'\n'): - data += b'\n' - return data.decode('utf-8') + data += '.' * 3 + return data def get_input_answer(case, archive): From dd725466e5c28ad3e2d0872558571ae77e7931b0 Mon Sep 17 00:00:00 2001 From: Phuoc Dinh Le <47278241+cuom1999@users.noreply.github.com> Date: Wed, 31 Mar 2021 21:46:42 -0500 Subject: [PATCH 2/3] Another attempt to fix VNese bugs with utf-8. --- judge/views/submission.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/judge/views/submission.py b/judge/views/submission.py index 4e278ac..6c7d9e6 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -139,7 +139,16 @@ def group_test_cases(cases): def read_head_archive(archive, file): with archive.open(file) as f: - return f.read(settings.TESTCASE_VISIBLE_LENGTH + 3) + s = f.read(settings.TESTCASE_VISIBLE_LENGTH + 3) + # add this so there are no characters left behind (ex, 'รก' = 2 utf-8 chars) + while True: + try: + s.decode('utf-8') + break + except UnicodeDecodeError: + s += f.read(1) + return s + def get_visible_content(data): data = data or b'' From 06318a97e5ba5b9be41e89c510af98fe673553a1 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 7 Apr 2021 14:08:42 -0500 Subject: [PATCH 3/3] Add name to import_users --- judge/tasks/experiment.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/judge/tasks/experiment.py b/judge/tasks/experiment.py index 7867170..f2e4b2f 100644 --- a/judge/tasks/experiment.py +++ b/judge/tasks/experiment.py @@ -25,8 +25,8 @@ def generate_report(problem): def import_users(csv_file): - # 1st row: username, password, organization - # ... row: a_username,passhere,organ + # 1st row: username, password, name, organization + # ... row: a_username, passhere, my_name, organ try: f = open(csv_file, 'r') except OSError: @@ -37,10 +37,14 @@ def import_users(csv_file): reader = csv.DictReader(f) for row in reader: - username = row['username'] - pwd = row['password'] - - user, _ = User.objects.get_or_create(username=username, defaults={ + try: + username = row['username'] + pwd = row['password'] + except Exception: + print('username and/or password column missing') + print('Make sure your columns are: username, password, name, organization') + + user, created = User.objects.get_or_create(username=username, defaults={ 'is_active': True, }) @@ -48,10 +52,18 @@ def import_users(csv_file): 'language': Language.get_python3(), 'timezone': settings.DEFAULT_USER_TIME_ZONE, }) + if created: + print('Created user', username) if pwd: user.set_password(pwd) - + elif created: + user.set_password('lqdoj') + print('User', username, 'missing password, default=lqdoj') + + if 'name' in row.keys() and row['name']: + user.first_name = row['name'] + if 'organization' in row.keys() and row['organization']: org = Organization.objects.get(name=row['organization']) profile.organizations.add(org)