diff --git a/edx_exams/apps/core/management/commands/bulk_add_course_staff.py b/edx_exams/apps/core/management/commands/bulk_add_course_staff.py index c6df05f1..b1948834 100644 --- a/edx_exams/apps/core/management/commands/bulk_add_course_staff.py +++ b/edx_exams/apps/core/management/commands/bulk_add_course_staff.py @@ -1,4 +1,4 @@ -"""Management command to populate the CourseStaffRole model and related User objects, from LMS""" +"""Management command to populate the CourseStaffRole model and related User objects, from LMS, using CSV""" import logging import unicodecsv @@ -15,12 +15,17 @@ class Command(BaseCommand): """ - todo: add docs here + Management command to add Course Staff (and User) in batches from CSV + """ + help = """ + Add Course Staff in bulk from CSV. + Expects that the data will be provided in a csv file format with the first row + being the header and columns being: username, email, role, course_id. + Example: + $ ... bulk_add_course_staff --csv_path=foo.csv """ - help = 'todo: Add help here' def add_arguments(self, parser): - # todo: should csv path be required? parser.add_argument( '-p', '--csv_path', metavar='csv_path', @@ -31,7 +36,7 @@ def add_arguments(self, parser): @transaction.atomic def handle(self, *args, **options): """ - todo: Main logic + The main logic and entry point of the management command """ csv_path = options['csv_path'] @@ -47,16 +52,17 @@ def add_course_staff_from_csv(self, csv_file): """ reader = list(unicodecsv.DictReader(csv_file)) for row in reader: - self.add_course_staff(row.get('username'), row.get('email'), row.get('role')) + self.add_course_staff(row.get('username'), row.get('email'), row.get('role'), row.get('course_id')) - def add_course_staff(self, username, email, role): - # todo: add error handling + def add_course_staff(self, username, email, role, course_id): + """ + Add course staff, in batches + """ + # todo: add error handling? user, _ = User.objects.get_or_create( username=username, email=email, ) - # todo: get course, where to get course? - course_id = '' # todo: add bulk create / batching CourseStaffRole.objects.get_or_create(