Skip to content
Snippets Groups Projects

Resolve "Provide import functionality via frontend for reviewers"

1 file
+ 3
3
Compare changes
  • Side-by-side
  • Inline
+ 13
6
@@ -3,6 +3,7 @@ import os
import readline
import logging
from rest_framework.exceptions import ValidationError
from util.messages import warn
from core.models import ExamType, Feedback, Submission, SubmissionType, Test, FeedbackLabel
from core.models import UserAccount as User
@@ -28,8 +29,8 @@ PASSWORDS = '.importer_passwords'
YES = 'Y/n'
NO = 'y/N'
RUSTY_HEKTOR_MIN_VER = ">=3.0.0"
RUSTY_HEKTOR_MAX_VER = "<4.0.0"
RUSTY_HEKTOR_MIN_VER = ">=4.0.0"
RUSTY_HEKTOR_MAX_VER = "<5.0.0"
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
@@ -119,11 +120,17 @@ def load_hektor_json():
with open(file, 'r') as f:
exam_data = json.JSONDecoder().decode(f.read())
parse_and_import_hektor_json(exam_data)
def parse_and_import_hektor_json(exam_data):
hektor_version = exam_data['meta']['version']
if not (semver.match(hektor_version, RUSTY_HEKTOR_MIN_VER) and
semver.match(hektor_version, RUSTY_HEKTOR_MAX_VER)):
warn(f'The data you\'re trying to import has the wrong version {hektor_version}\n'
f'Requirements: {RUSTY_HEKTOR_MIN_VER}, {RUSTY_HEKTOR_MAX_VER}')
raise ValidationError(
f'The data you\'re trying to import has the wrong version {hektor_version}\n'
f'Requirements: {RUSTY_HEKTOR_MIN_VER}, {RUSTY_HEKTOR_MAX_VER}'
)
exam, _ = ExamType.objects.get_or_create(**exam_data['module'])
@@ -131,7 +138,7 @@ def load_hektor_json():
_, created = SubmissionType.objects.update_or_create(
name=submission_type['name'], defaults=submission_type)
if not created:
log.warning(f"Updated submission type {submission_type}")
raise ValidationError(f"Updated submission type: {submission_type['name']}")
for student in exam_data['students']:
student_obj = user_factory.make_student(exam=exam, is_active=False,
@@ -151,7 +158,7 @@ def load_reviewers():
store_pw=True)
def add_submission(student_obj, code, tests, type=None):
def add_submission(student_obj, code, tests, type=None, display_code=None):
submission_type_obj = SubmissionType.objects.get(name=type)
submission_obj, _ = Submission.objects.update_or_create(
Loading