Skip to content
Snippets Groups Projects
Commit e18082dc authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Importer now works with rusty-hektor fixes #134

parent 815eb49d
No related branches found
No related tags found
1 merge request!138Resolve "Rework importer script to use new data format from rusty hektor"
Pipeline #88985 passed
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):
......
......@@ -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 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 = SubmissionType.objects.get(name=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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment