Merge pull request #12 from LQDJudge/master

Update VKU
This commit is contained in:
Phuoc Dinh Le 2021-04-08 15:21:12 -05:00 committed by GitHub
commit d6b8fb2223
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 12 deletions

View file

@ -25,8 +25,8 @@ def generate_report(problem):
def import_users(csv_file): def import_users(csv_file):
# 1st row: username, password, organization # 1st row: username, password, name, organization
# ... row: a_username,passhere,organ # ... row: a_username, passhere, my_name, organ
try: try:
f = open(csv_file, 'r') f = open(csv_file, 'r')
except OSError: except OSError:
@ -37,10 +37,14 @@ def import_users(csv_file):
reader = csv.DictReader(f) reader = csv.DictReader(f)
for row in reader: for row in reader:
try:
username = row['username'] username = row['username']
pwd = row['password'] pwd = row['password']
except Exception:
print('username and/or password column missing')
print('Make sure your columns are: username, password, name, organization')
user, _ = User.objects.get_or_create(username=username, defaults={ user, created = User.objects.get_or_create(username=username, defaults={
'is_active': True, 'is_active': True,
}) })
@ -48,9 +52,17 @@ def import_users(csv_file):
'language': Language.get_python3(), 'language': Language.get_python3(),
'timezone': settings.DEFAULT_USER_TIME_ZONE, 'timezone': settings.DEFAULT_USER_TIME_ZONE,
}) })
if created:
print('Created user', username)
if pwd: if pwd:
user.set_password(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']: if 'organization' in row.keys() and row['organization']:
org = Organization.objects.get(name=row['organization']) org = Organization.objects.get(name=row['organization'])

View file

@ -139,18 +139,27 @@ def group_test_cases(cases):
def read_head_archive(archive, file): def read_head_archive(archive, file):
with archive.open(file) as f: 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): def get_visible_content(data):
data = data or b'' data = data or b''
data = data.replace(b'\r\n', b'\r').replace(b'\r', b'\n') 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): if (len(data) > settings.TESTCASE_VISIBLE_LENGTH):
data = data[:settings.TESTCASE_VISIBLE_LENGTH] data = data[:settings.TESTCASE_VISIBLE_LENGTH]
data += b'.' * 3 data += '.' * 3
elif not data.endswith(b'\n'): return data
data += b'\n'
return data.decode('utf-8')
def get_input_answer(case, archive): def get_input_answer(case, archive):