diff --git a/util/factories.py b/util/factories.py index da49196e22bb4f0fdb84a7efc6629626d15fc016..6fedf552984211459306f71ba6fcf8293c59429f 100644 --- a/util/factories.py +++ b/util/factories.py @@ -1,6 +1,5 @@ import configparser -import secrets -import string +from xkcdpass import xkcd_password as xp from core import models from core.models import (ExamType, Feedback, StudentInfo, Submission, @@ -12,11 +11,12 @@ REVIEWERS = 'reviewers' PASSWORDS = '.importer_passwords' +words = xp.generate_wordlist(wordfile=xp.locate_wordfile(), min_length=5, max_length=8) -def get_random_password(length=32): + +def get_random_password(numwords=4): """ Returns a cryptographically random string of specified length """ - return ''.join(secrets.choice(string.ascii_lowercase) - for _ in range(length)) + return xp.generate_xkcdpassword(words, numwords=numwords, delimiter='-') def store_password(username, groupname, password): diff --git a/util/importer.py b/util/importer.py index e7475e8843e4a56930fb9b06e89b6e8f4592de16..610c5a060e591ff089f92b20fdcc434bfc9a797c 100644 --- a/util/importer.py +++ b/util/importer.py @@ -122,12 +122,17 @@ def add_tests(submission_obj, tests): add_feedback_if_test_recommends_it(test_obj) -def add_submission(student_obj, code, tests, type): - - submission_type = SubmissionType.objects.get(name=type) +# submission_type is the name outputted by rust_hektor, type the one from hektor +def add_submission(student_obj, code, tests, submission_type=None, type=None): + if submission_type is None and type is None: + raise Exception("Submission need to contain submission_type or type") + elif type is not None: + submission_type = type + + submission_type_obj = SubmissionType.objects.get(name=submission_type) submission_obj, _ = Submission.objects.update_or_create( - type=submission_type, + type=submission_type_obj, student=student_obj, defaults={'text': code} ) @@ -390,7 +395,6 @@ def do_load_submissions(): for student in exam_data['students']: student_obj = user_factory.make_student(**exam_obj, **student).student - for submission_obj in student['submissions']: add_submission(student_obj, **submission_obj)