From e18082dcb1f15bfd5ed1501824fecb06b42bab69 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Sun, 3 Feb 2019 17:51:39 +0100
Subject: [PATCH] Importer now works with rusty-hektor fixes #134

---
 util/factories.py | 10 +++++-----
 util/importer.py  | 12 ++++++++----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/util/factories.py b/util/factories.py
index da49196e..6fedf552 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 e7475e88..6a99b6db 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 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)
 
-- 
GitLab