lms.djangoapps.instructor_task.tasks_helper package

Contents

lms.djangoapps.instructor_task.tasks_helper package#

Submodules#

lms.djangoapps.instructor_task.tasks_helper.certs module#

Instructor tasks related to certificates.

lms.djangoapps.instructor_task.tasks_helper.certs.generate_students_certificates(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

For a given course_id, generate certificates for only students present in ‘students’ key in task_input json column, otherwise generate certificates for all enrolled students.

lms.djangoapps.instructor_task.tasks_helper.certs.students_require_certificate(course_id, enrolled_students, statuses_to_regenerate=None)#

Returns list of students where certificates needs to be generated. if ‘statuses_to_regenerate’ is given then return students that have Generated Certificates and the generated certificate status lies in ‘statuses_to_regenerate’

if ‘statuses_to_regenerate’ is not given then return all the enrolled student skipping the ones whose certificates have already been generated.

Parameters:
  • course_id

  • enrolled_students

  • statuses_to_regenerate

lms.djangoapps.instructor_task.tasks_helper.enrollments module#

Instructor tasks related to enrollments.

lms.djangoapps.instructor_task.tasks_helper.enrollments.process_student_enrollment_batch(_xblock_instance_args: Any, _entry_id: int, course_id: str | CourseKey, task_input: dict, action_name: str) dict#

Process a batch of student enrollment/unenrollment operations asynchronously.

Parameters:
  • _xblock_instance_args – XBlock instance arguments (unused)

  • _entry_id – The primary key for the InstructorTask entry

  • course_id – The course identifier (string or CourseKey)

  • task_input – Dictionary containing: - action: ‘enroll’ or ‘unenroll’ - identifiers: list of student identifiers (emails or usernames) - auto_enroll: boolean for auto-enrollment - email_students: boolean to send enrollment emails - reason: optional reason for enrollment change - secure: boolean indicating if request was secure (HTTPS) - site_id: optional site ID for notification emails

  • action_name – Name of the action being performed

Returns:

Task progress dictionary with results of enrollment operations

Return type:

dict

lms.djangoapps.instructor_task.tasks_helper.enrollments.upload_inactive_enrolled_students_info_csv(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

For a given course_id, generate a CSV file containing information about students who are enrolled in a course but have not activated their account yet, and store using a ReportStore.

lms.djangoapps.instructor_task.tasks_helper.enrollments.upload_may_enroll_csv(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

For a given course_id, generate a CSV file containing information about students who may enroll but have not done so yet, and store using a ReportStore.

lms.djangoapps.instructor_task.tasks_helper.enrollments.upload_students_csv(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

For a given course_id, generate a CSV file containing profile information for all students that are enrolled, and store using a ReportStore.

lms.djangoapps.instructor_task.tasks_helper.grades module#

Functionality for generating grade reports.

class lms.djangoapps.instructor_task.tasks_helper.grades.CourseGradeReport(context)#

Bases: GradeReportBase

Class to encapsulate functionality related to generating user/row had header data for Corse Grade Reports.

USER_BATCH_SIZE = 100#
classmethod generate(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

Public method to generate a grade report.

class lms.djangoapps.instructor_task.tasks_helper.grades.GradeReportBase(context)#

Bases: object

Base class for grade reports (ProblemGradeReport and CourseGradeReport).

log_additional_info_for_testing(message)#

Investigation logs for test problem grade report.

TODO – Remove as a part of PROD-1287

log_task_info(message)#

Updates the status on the celery task to the given message. Also logs the update.

class lms.djangoapps.instructor_task.tasks_helper.grades.InMemoryCourseGradeReport(context)#

Bases: CourseGradeReport, InMemoryReportMixin

Course Grade Report that compiles and then uploads all rows at once

class lms.djangoapps.instructor_task.tasks_helper.grades.InMemoryProblemGradeReport(context)#

Bases: ProblemGradeReport, InMemoryReportMixin

Program Grade Report that compiles and then uploads all rows at once

class lms.djangoapps.instructor_task.tasks_helper.grades.InMemoryReportMixin#

Bases: object

Mixin for a file report that will generate file in memory and then upload to report store

class lms.djangoapps.instructor_task.tasks_helper.grades.ProblemGradeReport(context)#

Bases: GradeReportBase

Class to encapsulate functionality related to generating user/row had header data for Problem Grade Reports.

classmethod generate(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

Public method to generate a grade report.

class lms.djangoapps.instructor_task.tasks_helper.grades.ProblemResponses#

Bases: object

Class to encapsulate functionality related to generating Problem Responses Reports.

classmethod generate(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

For a given course_id, generate a CSV file containing all student answers to a given problem, and store using a ReportStore.

class lms.djangoapps.instructor_task.tasks_helper.grades.TempFileCourseGradeReport(context)#

Bases: CourseGradeReport, TemporaryFileReportMixin

Course Grade Report that writes file iteratively to a TempFile to then be uploaded

class lms.djangoapps.instructor_task.tasks_helper.grades.TempFileProblemGradeReport(context)#

Bases: ProblemGradeReport, TemporaryFileReportMixin

Program Grade Report that writes file iteratively to a TempFile to then be uploaded

class lms.djangoapps.instructor_task.tasks_helper.grades.TemporaryFileReportMixin#

Bases: object

Mixin for a file report that will write rows iteratively to a TempFile

iter_and_write_batched_rows(batched_rows, success_file, error_file)#

Iterate through batched rows, writing returned chunks to disk as we go. This should hopefully help us avoid out of memory errors.

upload_temp_files(success_file, error_file, has_errors)#

Uploads success and error csv files to report store

lms.djangoapps.instructor_task.tasks_helper.misc module#

This file contains tasks that are designed to perform background operations on the running state of a course.

lms.djangoapps.instructor_task.tasks_helper.misc.cohort_students_and_upload(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

Within a given course, cohort students in bulk, then upload the results using a ReportStore.

lms.djangoapps.instructor_task.tasks_helper.misc.generate_anonymous_ids(_xblock_instance_args, _entry_id, course_id, task_input, action_name)#

Generate a 2-column CSV output of user-id, anonymized-user-id

lms.djangoapps.instructor_task.tasks_helper.misc.upload_course_survey_report(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

For a given course_id, generate a html report containing the survey results for a course.

lms.djangoapps.instructor_task.tasks_helper.misc.upload_ora2_data(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

Collect ora2 responses and upload them to S3 as a CSV

lms.djangoapps.instructor_task.tasks_helper.misc.upload_ora2_submission_files(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

Creates zip archive with submission files in three steps:

  1. Collect all files information using ORA download helper.

  2. Download all submission attachments, put them in temporary zip

    file along with submission texts and csv downloads list.

  3. Upload zip file into reports storage.

lms.djangoapps.instructor_task.tasks_helper.misc.upload_ora2_summary(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

Collect ora2/student summaries and upload them to file storage as a CSV

lms.djangoapps.instructor_task.tasks_helper.misc.upload_proctored_exam_results_report(_xblock_instance_args, _entry_id, course_id, _task_input, action_name)#

For a given course_id, generate a CSV file containing information about proctored exam results, and store using a ReportStore.

lms.djangoapps.instructor_task.tasks_helper.module_state module#

Instructor Tasks related to module state.

lms.djangoapps.instructor_task.tasks_helper.module_state.delete_problem_module_state(xblock_instance_args, _block, student_module, _task_input)#

Delete the StudentModule entry.

Always returns UPDATE_STATUS_SUCCEEDED, indicating success, if it doesn’t raise an exception due to database error.

lms.djangoapps.instructor_task.tasks_helper.module_state.override_score_module_state(xblock_instance_args, block, student_module, task_input)#

Takes an XBlock and a corresponding StudentModule object, and performs an override on the student’s problem score.

Throws exceptions if the override is fatal and should be aborted if in a loop. In particular, raises UpdateProblemModuleStateError if module fails to instantiate, or if the module doesn’t support overriding, or if the score used for override is outside the acceptable range of scores (between 0 and the max score for the problem).

Returns True if problem was successfully overriden for the given student, and False if problem encountered some kind of error in overriding.

lms.djangoapps.instructor_task.tasks_helper.module_state.perform_module_state_update(update_fcn, filter_fcn, _entry_id, course_id, task_input, action_name)#

Performs generic update by visiting StudentModule instances with the update_fcn provided.

The student modules are fetched for update the update_fcn is called on each StudentModule that passes the resulting filtering. It is passed four arguments: the block for the module pointed to by the module_state_key, the particular StudentModule to update, the xblock_instance_args, and the task_input being passed through. If the value returned by the update function evaluates to a boolean True, the update is successful; False indicates the update on the particular student module failed. A raised exception indicates a fatal condition – that no other student modules should be considered.

The return value is a dict containing the task’s results, with the following keys:

‘attempted’: number of attempts made ‘succeeded’: number of attempts that “succeeded” ‘skipped’: number of attempts that “skipped” ‘failed’: number of attempts that “failed” ‘total’: number of possible updates to attempt ‘action_name’: user-visible verb to use in status messages. Should be past-tense.

Pass-through of input action_name.

‘duration_ms’: how long the task has (or had) been running.

Because this is run internal to a task, it does not catch exceptions. These are allowed to pass up to the next level, so that it can set the failure modes and capture the error trace in the InstructorTask and the result object.

lms.djangoapps.instructor_task.tasks_helper.module_state.rescore_problem_module_state(xblock_instance_args, block, student_module, task_input)#

Takes an XBlock and a corresponding StudentModule object, and performs rescoring on the student’s problem submission.

Throws exceptions if the rescoring is fatal and should be aborted if in a loop. In particular, raises UpdateProblemModuleStateError if module fails to instantiate, or if the module doesn’t support rescoring.

Returns True if problem was successfully rescored for the given student, and False if problem encountered some kind of error in rescoring.

lms.djangoapps.instructor_task.tasks_helper.module_state.reset_attempts_module_state(xblock_instance_args, _block, student_module, _task_input)#

Resets problem attempts to zero for specified student_module.

Returns a status of UPDATE_STATUS_SUCCEEDED if a problem has non-zero attempts that are being reset, and UPDATE_STATUS_SKIPPED otherwise.

lms.djangoapps.instructor_task.tasks_helper.runner module#

Instrutor Task runner

class lms.djangoapps.instructor_task.tasks_helper.runner.TaskProgress(action_name, total, start_time)#

Bases: object

Encapsulates the current task’s progress by keeping track of ‘attempted’, ‘succeeded’, ‘skipped’, ‘failed’, ‘total’, ‘action_name’, and ‘duration_ms’ values.

property state#
update_task_state(extra_meta=None)#

Update the current celery task’s state to the progress state specified by the current object. Returns the progress dictionary for use by run_main_task and BaseInstructorTask.on_success.

Parameters:

extra_meta (dict) – Extra metadata to pass to update_state

Returns:

The current task’s progress dict

Return type:

dict

lms.djangoapps.instructor_task.tasks_helper.runner.run_main_task(entry_id, task_fcn, action_name)#

Applies the task_fcn to the arguments defined in entry_id InstructorTask.

Arguments passed to task_fcn are:

entry_id : the primary key for the InstructorTask entry representing the task. course_id : the id for the course. task_input : dict containing task-specific arguments, JSON-decoded from InstructorTask’s task_input. action_name : past-tense verb to use for constructing status messages.

If no exceptions are raised, the task_fcn should return a dict containing the task’s result with the following keys:

‘attempted’: number of attempts made ‘succeeded’: number of attempts that “succeeded” ‘skipped’: number of attempts that “skipped” ‘failed’: number of attempts that “failed” ‘total’: number of possible subtasks to attempt ‘action_name’: user-visible verb to use in status messages.

Should be past-tense. Pass-through of input action_name.

‘duration_ms’: how long the task has (or had) been running.

lms.djangoapps.instructor_task.tasks_helper.utils module#

Utility methods for instructor tasks

lms.djangoapps.instructor_task.tasks_helper.utils.tracker_emit(report_name)#

Emits a ‘report.requested’ event for the given report.

lms.djangoapps.instructor_task.tasks_helper.utils.upload_csv_file_to_report_store(file, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD', parent_dir='')#

Upload data as a CSV using ReportStore.

Parameters:
  • rows – CSV data in a file-like object

  • csv_name – Name of the resulting CSV

  • course_id – ID of the course

  • parent_dor – Name of the directory where the CSV file will be stored

Returns:

string - Name of the generated report

Return type:

report_name

lms.djangoapps.instructor_task.tasks_helper.utils.upload_csv_to_report_store(rows, csv_name, course_id, timestamp, config_name='GRADES_DOWNLOAD', parent_dir='')#

Upload data as a CSV using ReportStore.

Parameters:
  • rows

    CSV data in the following format (first column may be a header): [

    [row1_colum1, row1_colum2, …], …

    ]

  • csv_name – Name of the resulting CSV

  • course_id – ID of the course

  • parent_dor – Name of the directory where the CSV file will be stored

Returns:

string - Name of the generated report

Return type:

report_name

lms.djangoapps.instructor_task.tasks_helper.utils.upload_zip_to_report_store(file, zip_name, course_id, timestamp, config_name='GRADES_DOWNLOAD')#

Upload given file buffer as a zip file using ReportStore.

Module contents#