[WIP] Management command to launch a grade report


*Work in progress*.
This pull request serves to ask to edX:

  • is there interest in merging this feature?

  • what changes would need to happen to merge it upstream? In particular, what Python APIs can we contribute

This PR adds a `generate_csv_grade_reports` management command that launches the grade report for the selected course (or for all courses). It's equivalent to clicking the `Generate grade report` button in the instructor dashboard, but since it's a management command it can be automated in a cron job to launch these reports every day. This is specially useful to launch reports during the night, when the server load is lower (since those reports are resource-intensive).

To run it:
`./manage.py lms generate_csv_grade_reports --requester adminstaff --courses course-v1:edX+DemoX+Demo_Course course-v1CL+TE1+2018-01`

*JIRA tickets*: unknown. This is SE-1643 internally

*Dependencies*: None

*Screenshots*: None

*Sandbox URL*: N/A.

*Merge deadline*: None

*Testing instructions*:

1. See command above. Use your username as requester (tasks need to have an owner)
2. Go to that course's instructor dashboard. You'll see a newly launched grade report job
3. Wait until it finishes. You'll be able to download the report in the same way as if you had clicked the button yourself
4. Repeat tests for: two or more courses (comma-separated), or all courses. TODO: more detailed test instructions for this

*Author notes and concerns*:

The code works, but it's still ugly because it calls private methods from `api_helper.py`. We'd like to validate the approach before we add new APIs.

Some next steps/options are:
1. the current [submit_task](https://github.com/open-craft/edx-platform/blob/dbdde489c6f05b93689e3e7645394b29ea0e5763/lms/djangoapps/instructor_task/api_helper.py#L428) requires a `request` object to extract the username. We could change the function signature so that it accept a `request` object or, if it's None, a username
2. or we could add a parallel function, like `submit_task` but without requiring a `request` object. This could be in `api.py` (besides `ap_helper.py`)
3. or pass a fake `request` object and avoid changing the `api_helper` code

Other major direction changes would be:

  • to be able to launch a grade report without specifying any username. Let it be shown as admin or system

  • to make this management command be able to automate any type of report, not only the grade report

  • to add a web UI to customize the automatic launching of reports


  • [ ] @swalladge

  • [ ] edX reviewer[s] TBD


Nimisha Asthagiri


Open Source Pull Request Bot


Contributor Name

Daniel Clemente Laboreo




Epic Link


OSCM Assignee


Platform Map Area (Levels 1 & 2)

Educator Experiences - Course Operations

Platform Map Area (Levels 3 & 4)


Blended Hour Utilization Percentage