commit
882194d453
2 changed files with 42 additions and 6 deletions
|
@ -1,6 +1,10 @@
|
||||||
from collections import defaultdict
|
from django.contrib.auth.models import User
|
||||||
from judge.models import SubmissionTestCase, Problem
|
from django.conf import settings
|
||||||
|
|
||||||
|
from judge.models import SubmissionTestCase, Problem, Profile, Language, Organization
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
import csv
|
||||||
|
|
||||||
def generate_report(problem):
|
def generate_report(problem):
|
||||||
testcases = SubmissionTestCase.objects.filter(submission__problem=problem).all()
|
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):
|
for i, _ in sorted(rate.items(), key=lambda x: x[1], reverse=True):
|
||||||
print(i, score[i], total[i], rate[i])
|
print(i, score[i], total[i], rate[i])
|
||||||
|
|
||||||
def test(code):
|
|
||||||
problem = Problem.objects.get(code=code)
|
def import_users(csv_file):
|
||||||
generate_report(problem)
|
# 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()
|
||||||
|
|
|
@ -541,7 +541,7 @@ def problem_submit(request, problem, submission=None):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
user_logger.info('Naughty user %s wants to submit to %s without permission',
|
user_logger.info('Naughty user %s wants to submit to %s without permission',
|
||||||
request.user.username, problem.code)
|
request.user.username, problem.code)
|
||||||
return HttpResponseForbidden('<h1>Do you want me to ban you?</h1>')
|
return HttpResponseForbidden('<h1>Not allowed to submit. Try later.</h1>')
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
if problem.is_editable_by(request.user):
|
if problem.is_editable_by(request.user):
|
||||||
|
|
Loading…
Reference in a new issue