Skip to content

Commit

Permalink
[JSON import] Add management command for import
Browse files Browse the repository at this point in the history
  • Loading branch information
hansegucker committed Jun 17, 2024
1 parent 4914f98 commit a886322
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions evap/staff/management/commands/json_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json
import logging

from django.core.management.base import BaseCommand

from evap.evaluation.management.commands.tools import log_exceptions
from evap.evaluation.models import Semester
from evap.staff.importers.json import JSONImporter

logger = logging.getLogger(__name__)


@log_exceptions
class Command(BaseCommand):
help = "Import enrollments from JSON file."

def add_arguments(self, parser):
# Positional arguments
parser.add_argument("semester", type=int)
parser.add_argument("file", type=str)

def handle(self, *args, **options):
print(args, options)
try:
semester = Semester.objects.get(pk=options["semester"])
except Semester.DoesNotExist:
self.stdout.write(self.style.ERROR("Semester does not exist."))
return

with open(options["file"]) as file:

import_dict = json.load(file)
importer = JSONImporter(semester)
importer.import_json(import_dict)

0 comments on commit a886322

Please sign in to comment.