Skip to content

Commit

Permalink
docs: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Mar 7, 2024
1 parent 54b43c5 commit a974b96
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions edx_exams/apps/core/management/commands/bulk_add_course_staff.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 2 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L2

Added line #L2 was not covered by tests

import unicodecsv
Expand All @@ -15,12 +15,17 @@

class Command(BaseCommand):

Check warning on line 16 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L16

Added line #L16 was not covered by tests
"""
todo: add docs here
Management command to add Course Staff (and User) in batches from CSV
"""
help = """

Check warning on line 20 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L20

Added line #L20 was not covered by tests
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(

Check warning on line 29 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L28-L29

Added lines #L28 - L29 were not covered by tests
'-p', '--csv_path',
metavar='csv_path',
Expand All @@ -31,7 +36,7 @@ def add_arguments(self, parser):
@transaction.atomic
def handle(self, *args, **options):

Check warning on line 37 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L36-L37

Added lines #L36 - L37 were not covered by tests
"""
todo: Main logic
The main logic and entry point of the management command
"""
csv_path = options['csv_path']

Check warning on line 41 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L41

Added line #L41 was not covered by tests

Expand All @@ -47,16 +52,17 @@ def add_course_staff_from_csv(self, csv_file):
"""
reader = list(unicodecsv.DictReader(csv_file))

Check warning on line 53 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L53

Added line #L53 was not covered by tests
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'))

Check warning on line 55 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L55

Added line #L55 was not covered by tests

def add_course_staff(self, username, email, role):
# todo: add error handling
def add_course_staff(self, username, email, role, course_id):

Check warning on line 57 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L57

Added line #L57 was not covered by tests
"""
Add course staff, in batches
"""
# todo: add error handling?
user, _ = User.objects.get_or_create(

Check warning on line 62 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L62

Added line #L62 was not covered by tests
username=username,
email=email,
)
# todo: get course, where to get course?
course_id = ''

# todo: add bulk create / batching
CourseStaffRole.objects.get_or_create(

Check warning on line 68 in edx_exams/apps/core/management/commands/bulk_add_course_staff.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/core/management/commands/bulk_add_course_staff.py#L68

Added line #L68 was not covered by tests
Expand Down

0 comments on commit a974b96

Please sign in to comment.