From 34305c8ec9ef8df3631754d12c7d8094656c8b1f Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Thu, 28 Jan 2021 22:42:53 -0600 Subject: [PATCH 1/2] Change wording --- judge/views/problem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/judge/views/problem.py b/judge/views/problem.py index e5ba33c..a366ef5 100644 --- a/judge/views/problem.py +++ b/judge/views/problem.py @@ -541,7 +541,7 @@ def problem_submit(request, problem, submission=None): if request.method == 'POST': user_logger.info('Naughty user %s wants to submit to %s without permission', request.user.username, problem.code) - return HttpResponseForbidden('

Do you want me to ban you?

') + return HttpResponseForbidden('

Not allowed to submit. Try later.

') raise Http404() if problem.is_editable_by(request.user): From 6f7e5f51730a4911ad052d905bfe4119a36c7937 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Thu, 28 Jan 2021 22:43:10 -0600 Subject: [PATCH 2/2] Add import users --- judge/tasks/experiment.py | 46 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/judge/tasks/experiment.py b/judge/tasks/experiment.py index 12ea1ca..7867170 100644 --- a/judge/tasks/experiment.py +++ b/judge/tasks/experiment.py @@ -1,6 +1,10 @@ -from collections import defaultdict -from judge.models import SubmissionTestCase, Problem +from django.contrib.auth.models import User +from django.conf import settings +from judge.models import SubmissionTestCase, Problem, Profile, Language, Organization + +from collections import defaultdict +import csv def generate_report(problem): testcases = SubmissionTestCase.objects.filter(submission__problem=problem).all() @@ -19,6 +23,38 @@ def generate_report(problem): for i, _ in sorted(rate.items(), key=lambda x: x[1], reverse=True): print(i, score[i], total[i], rate[i]) -def test(code): - problem = Problem.objects.get(code=code) - generate_report(problem) \ No newline at end of file + +def import_users(csv_file): + # 1st row: username, password, organization + # ... row: a_username,passhere,organ + try: + f = open(csv_file, 'r') + except OSError: + print("Could not open csv file", csv_file) + return + + with f: + reader = csv.DictReader(f) + + for row in reader: + username = row['username'] + pwd = row['password'] + + user, _ = User.objects.get_or_create(username=username, defaults={ + 'is_active': True, + }) + + profile, _ = Profile.objects.get_or_create(user=user, defaults={ + 'language': Language.get_python3(), + 'timezone': settings.DEFAULT_USER_TIME_ZONE, + }) + + if pwd: + user.set_password(pwd) + + if 'organization' in row.keys() and row['organization']: + org = Organization.objects.get(name=row['organization']) + profile.organizations.add(org) + + user.save() + profile.save()