lms.djangoapps.instructor.views package#
Submodules#
lms.djangoapps.instructor.views.api module#
Instructor Dashboard API views
JSON views which the instructor dashboard requests.
Many of these GETs may become PUTs in the future.
- class lms.djangoapps.instructor.views.api.CohortCSV(**kwargs)#
Bases:
DeveloperErrorViewMixin,APIViewUse Cases
Submit a CSV file to assign users to cohorts
Example Requests:
POST /api/cohorts/v1/courses/{course_id}/users/
- Response Values
Empty as this is executed asynchronously.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'rest_framework.permissions.IsAdminUser'>)#
- post(request, course_key_string)#
View method that accepts an uploaded file (using key “uploaded-file”) containing cohort assignments for users. This method spawns a celery task to do the assignments, and a CSV file with results is provided via data downloads.
- class lms.djangoapps.instructor.views.api.InstructorTaskSerializer(*args, **kwargs)#
Bases:
SerializerSerializer that describes the format of a single instructor task.
- class lms.djangoapps.instructor.views.api.InstructorTasks(**kwargs)#
Bases:
DeveloperErrorViewMixin,APIViewUse Cases
Lists currently running instructor tasks
- Parameters
With no arguments, lists running tasks.
problem_location_str lists task history for problem
- problem_location_str and unique_student_identifier lists task
history for problem AND student (intersection)
Example Requests:
GET /courses/{course_id}/instructor/api/v0/tasks
- Response Values
- {
- “tasks”: [
- {
“status”: “Incomplete”, “task_type”: “grade_problems”, “task_id”: “2519ff31-22d9-4a62-91e2-55495895b355”, “created”: “2019-01-15T18:00:15.902470+00:00”, “task_input”: “{}”, “duration_sec”: “unknown”, “task_message”: “No status information available”, “requester”: “staff”, “task_state”: “PROGRESS”
}
]
}
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- get(request, course_id)#
List instructor tasks filtered by course_id.
Use Cases
Lists currently running instructor tasks
- Parameters
With no arguments, lists running tasks.
problem_location_str lists task history for problem
- problem_location_str and unique_student_identifier lists task
history for problem AND student (intersection)
Example Requests:
GET /courses/{course_id}/instructor/api/v0/tasks
- {
- “tasks”: [
- {
“status”: “Incomplete”, “task_type”: “grade_problems”, “task_id”: “2519ff31-22d9-4a62-91e2-55495895b355”, “created”: “2019-01-15T18:00:15.902470+00:00”, “task_input”: “{}”, “duration_sec”: “unknown”, “task_message”: “No status information available”, “requester”: “staff”, “task_state”: “PROGRESS”
}
]
}
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- class lms.djangoapps.instructor.views.api.InstructorTasksListSerializer(*args, **kwargs)#
Bases:
SerializerSerializer to describe the response of the instructor tasks list API.
- class lms.djangoapps.instructor.views.api.ProblemResponseReportInitiate(**kwargs)#
Bases:
DeveloperErrorViewMixin,APIViewInitiate generation of a CSV file containing all student answers to a given problem.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request, course_id)#
Initiate generation of a CSV file containing all student answers to a given problem.
Example requests
- POST /api/instructor/v1/reports/{course_id}/generate/problem_responses {
- “problem_locations”: [
“{usage_key1}”, “{usage_key2}”, “{usage_key3}”
]
} POST /api/instructor/v1/reports/{course_id}/generate/problem_responses {
“problem_locations”: [“{usage_key}”], “problem_types_filter”: [“problem”]
}
POST Parameters
A POST request can include the following parameters:
problem_location: A list of usage keys for the blocks to include in the report. If the location is a block that contains other blocks, (such as the course, section, subsection, or unit blocks) then all blocks under that block will be included in the report.
problem_types_filter: Optional. A comma-separated list of block types to include in the report. If set, only blocks of the specified types will be included in the report.
To get data on all the poll and survey blocks in a course, you could POST the usage key of the course for problem_location, and “poll, survey” as the value for problem_types_filter.
Example Response: If initiation is successful (or generation task is already running): ```json {
“status”: “The problem responses report is being created. …”, “task_id”: “4e49522f-31d9-431a-9cff-dd2a2bf4c85a”
}#
Responds with BadRequest if any of the provided problem locations are faulty.
- class lms.djangoapps.instructor.views.api.ProblemResponseReportPostParamsSerializer(*args, **kwargs)#
Bases:
SerializerSerializer that describes that POST parameters for the report generation API.
- class lms.djangoapps.instructor.views.api.ProblemResponsesReportStatusSerializer(*args, **kwargs)#
Bases:
SerializerSerializer that describes the response of the problem response report generation API.
- class lms.djangoapps.instructor.views.api.ReportDownloadSerializer(*args, **kwargs)#
Bases:
SerializerSerializer that describes a single report download.
- class lms.djangoapps.instructor.views.api.ReportDownloads(**kwargs)#
Bases:
DeveloperErrorViewMixin,APIViewAPI view to list report downloads for a course.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- get(request, course_id)#
List report CSV files that are available for download for this course.
Use Cases
Lists reports available for download
Example Requests:
GET /api/instructor/v1/reports/{course_id}
- “downloads”: [
- {
“url”: “https://1.mock.url”, “link”: “<a href=”https://1.mock.url”>mock_file_name_1</a>”, “name”: “mock_file_name_1”
}
]
}#
The report name will depend on the type of report generated. For example a problem responses report for an entire course might be called:
edX_DemoX_Demo_Course_student_state_from_block-v1_edX+DemoX+Demo_Course+type@course+block@course_2021-04-30-0918.csv
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- class lms.djangoapps.instructor.views.api.ReportDownloadsListSerializer(*args, **kwargs)#
Bases:
SerializerSerializer that describes the response of the report downloads list API.
- lms.djangoapps.instructor.views.api.add_certificate_exception(course_key, student, certificate_exception)#
Add a certificate exception.
Raises ValueError in case Student is already allowlisted or if they appear on the block list.
- Parameters:
course_key – identifier of the course whose certificate exception will be added.
student – User object whose certificate exception will be added.
certificate_exception – A dict object containing certificate exception info.
- Returns:
Allowlist item in dict format containing certificate exception info.
- lms.djangoapps.instructor.views.api.add_users_to_cohorts(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.bulk_beta_modify_access(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.calculate_grades_csv(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.certificate_exception_view(request, course_id)#
Add/Remove students to/from the certificate allowlist.
- Parameters:
request – HttpRequest object
course_id – course identifier of the course for whom to add/remove certificates exception.
- Returns:
JsonResponse object with success/error message or certificate exception data.
- lms.djangoapps.instructor.views.api.certificate_invalidation_view(request, course_id)#
Invalidate/Re-Validate students to/from certificate.
- Parameters:
request – HttpRequest object
course_id – course identifier of the course for whom to add/remove certificates exception.
- Returns:
JsonResponse object with success/error message or certificate invalidation data.
- lms.djangoapps.instructor.views.api.common_exceptions_400(func)#
Catches common exceptions and renders matching 400 errors. (decorator without arguments)
- lms.djangoapps.instructor.views.api.create_and_enroll_user(email, username, name, country, password, course_id, course_mode, enrolled_by, email_params, email_user=True)#
- Create a new user and enroll him/her to the given course, return list of errors in the following format
- Error format:
each error is key-value pait dict with following key-value pairs. 1. username: username of the user to enroll 1. email: email of the user to enroll 1. response: readable error message
- Parameters:
email – user’s email address
username – user’s username
name – user’s name
country – user’s country
password – user’s password
course_id – course identifier of the course in which to enroll the user.
course_mode – mode for user enrollment, e.g. ‘honor’, ‘audit’ etc.
enrolled_by – User who made the manual enrollment entry (usually instructor or support)
email_params – information to send to the user via email
email_user – If True and it’s a new user, an email will be sent to them upon account creation.
- Returns:
list of errors
- lms.djangoapps.instructor.views.api.create_manual_course_enrollment(user, course_id, mode, enrolled_by, reason, state_transition)#
Create course enrollment for the given student and create manual enrollment audit trail.
- Parameters:
user – User who is to enroll in course
course_id – course identifier of the course in which to enroll the user.
mode – mode for user enrollment, e.g. ‘honor’, ‘audit’ etc.
enrolled_by – User who made the manual enrollment entry (usually instructor or support)
reason – Reason behind manual enrollment
state_transition – state transition denoting whether student enrolled from un-enrolled, un-enrolled from enrolled etc.
:return CourseEnrollment instance.
- lms.djangoapps.instructor.views.api.create_user_and_user_profile(email, username, name, country, password)#
Create a new user, add a new Registration instance for letting user verify its identity and create a user profile.
- Parameters:
email – user’s email address
username – user’s username
name – user’s name
country – user’s country
password – user’s password
- Returns:
User instance of the new user.
- lms.djangoapps.instructor.views.api.enable_certificate_generation(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.export_ora2_data(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.export_ora2_submission_files(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.export_ora2_summary(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.generate_bulk_certificate_exceptions(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.generate_certificate_exceptions(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.generate_random_string(length)#
Create a string of random characters of specified length
- lms.djangoapps.instructor.views.api.generate_unique_password(generated_passwords, password_length=12)#
generate a unique password for each student.
- lms.djangoapps.instructor.views.api.get_anon_ids(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_course_survey_results(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_grading_config(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_issued_certificates(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_problem_responses(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_proctored_exam_results(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_student(username_or_email)#
Retrieve and return User object from db, raise ValueError if user is does not exists or is not enrolled in the given course.
- Parameters:
username_or_email – String containing either user name or email of the student.
course_key – CourseKey object identifying the current course.
- Returns:
User object
- lms.djangoapps.instructor.views.api.get_student_enrollment_status(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_student_progress_url(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_students_features(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_students_who_may_enroll(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.get_user_invoice_preference(request, course_id)#
Gets invoice copy user’s preferences.
- lms.djangoapps.instructor.views.api.invalidate_certificate(request, generated_certificate, certificate_invalidation_data, student)#
Invalidate given GeneratedCertificate and add CertificateInvalidation record for future reference or re-validation.
- Parameters:
request – HttpRequest object
generated_certificate – GeneratedCertificate object, the certificate we want to invalidate
certificate_invalidation_data – dict object containing data for CertificateInvalidation.
student – User object, this user is tied to the generated_certificate we are going to invalidate
- Returns:
dict object containing updated certificate invalidation data.
- lms.djangoapps.instructor.views.api.list_background_email_tasks(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_course_role_members(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_email_content(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_entrance_exam_instructor_tasks(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_financial_report_downloads(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_forum_members(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.list_instructor_tasks(request, course_id)#
List instructor tasks.
- Takes optional query parameters.
With no arguments, lists running tasks.
problem_location_str lists task history for problem
- problem_location_str and unique_student_identifier lists task
history for problem AND student (intersection)
- lms.djangoapps.instructor.views.api.list_report_downloads(request, course_id)#
List grade CSV files that are available for download for this course.
Takes the following query parameters: - (optional) report_name - name of the report
- lms.djangoapps.instructor.views.api.mark_student_can_skip_entrance_exam(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.modify_access(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.override_problem_score(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.parse_request_data(request)#
Parse and return request data, raise ValueError in case of invalid JSON data.
- Parameters:
request – HttpRequest request object.
- Returns:
dict object containing parsed json data.
- lms.djangoapps.instructor.views.api.parse_request_data_and_get_user(request)#
Parse request data into Certificate Exception and User object. Certificate Exception is the dict object containing information about certificate exception.
- Parameters:
request –
course_key – Course Identifier of the course for whom to process certificate exception
- Returns:
key-value pairs containing certificate exception data and User object
- lms.djangoapps.instructor.views.api.problem_grade_report(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.re_validate_certificate(request, *args, **kwargs)#
- lms.djangoapps.instructor.views.api.register_and_enroll_students(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.remove_certificate_exception(course_key, student)#
Remove certificate exception for given course and student from the certificate allowlist.
Raises ValueError if an error occurs during removal of the allowlist entry.
- Parameters:
course_key – identifier of the course whose certificate exception needs to be removed.
student – User object whose certificate exception needs to be removed.
- Returns:
- lms.djangoapps.instructor.views.api.require_course_permission(permission)#
Decorator with argument that requires a specific permission of the requesting user. If the requirement is not satisfied, returns an HttpResponseForbidden (403).
Assumes that request is in args[0]. Assumes that course_id is in kwargs[‘course_id’].
- lms.djangoapps.instructor.views.api.require_finance_admin(func)#
Decorator for checking finance administrator access before executing an HTTP endpoint. This decorator is designed to be used for a request based action on a course. It assumes that there will be a request object as well as a course_id attribute to leverage to check course level privileges.
If the user does not have privileges for this operation, this will return HttpResponseForbidden (403).
- lms.djangoapps.instructor.views.api.require_post_params(*args, **kwargs)#
Checks for required parameters or renders a 400 error. (decorator with arguments)
args is a *list of required POST parameter names. kwargs is a **dict of required POST parameter names
to string explanations of the parameter
- lms.djangoapps.instructor.views.api.require_sales_admin(func)#
Decorator for checking sales administrator access before executing an HTTP endpoint. This decorator is designed to be used for a request based action on a course. It assumes that there will be a request object as well as a course_id attribute to leverage to check course level privileges.
If the user does not have privileges for this operation, this will return HttpResponseForbidden (403).
- lms.djangoapps.instructor.views.api.rescore_entrance_exam(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.rescore_problem(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.reset_student_attempts(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.reset_student_attempts_for_entrance_exam(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.send_email(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.start_certificate_generation(request, *args, **kwargs)#
- lms.djangoapps.instructor.views.api.start_certificate_regeneration(request, *args, **kwargs)#
- lms.djangoapps.instructor.views.api.students_update_enrollment(*args, **kwargs)#
- lms.djangoapps.instructor.views.api.update_forum_role_membership(*args, **kwargs)#
lms.djangoapps.instructor.views.api_urls module#
Instructor API endpoint urls.
lms.djangoapps.instructor.views.gradebook_api module#
Grade book view for instructor and pagination work (for grade book) which is currently use by ccx and instructor apps.
- lms.djangoapps.instructor.views.gradebook_api.calculate_page_info(offset, total_students)#
Takes care of sanitizing the offset of current page also calculates offsets for next and previous page and information like total number of pages and current page number.
- Parameters:
offset – offset for database query
- Returns:
tuple consist of page number, query offset for next and previous pages and valid offset
- lms.djangoapps.instructor.views.gradebook_api.get_grade_book_page(request, course, course_key)#
Get student records per page along with page information i.e current page, total pages and offset information.
lms.djangoapps.instructor.views.instructor_dashboard module#
Instructor Dashboard Views
- class lms.djangoapps.instructor.views.instructor_dashboard.InstructorDashboardTab(tab_dict)#
Bases:
CourseTabDefines the Instructor Dashboard view type that is shown as a course tab.
- is_dynamic = True#
- classmethod is_enabled(course, user=None)#
Returns true if the specified user has staff access.
- priority = 300#
- title = 'Instructor'#
- type = 'instructor'#
- view_name = 'instructor_dashboard'#
- lms.djangoapps.instructor.views.instructor_dashboard.instructor_dashboard_2(request, course_id)#
Display the instructor dashboard for a course.
- lms.djangoapps.instructor.views.instructor_dashboard.is_ecommerce_course(course_key)#
Checks if the given course is an e-commerce course or not, by checking its SKU value from CourseMode records for the course
- lms.djangoapps.instructor.views.instructor_dashboard.null_applicable_aside_types(block)#
get_aside method for monkey-patching into applicable_aside_types while rendering an HtmlBlock for email text editing. This returns an empty list.
- lms.djangoapps.instructor.views.instructor_dashboard.set_course_mode_price(request, course_id)#
set the new course price and add new entry in the CourseModesArchive Table
- lms.djangoapps.instructor.views.instructor_dashboard.show_analytics_dashboard_message(course_key)#
Defines whether or not the analytics dashboard URL should be displayed.
- Parameters:
course_key (CourseLocator) – The course locator to display the analytics dashboard message on.
lms.djangoapps.instructor.views.instructor_task_helpers module#
A collection of helper utility functions for working with instructor tasks.
- lms.djangoapps.instructor.views.instructor_task_helpers.email_error_information()#
Returns email information marked as None, used in event email cannot be loaded
- lms.djangoapps.instructor.views.instructor_task_helpers.extract_email_features(email_task)#
From the given task, extract email content information
Expects that the given task has the following attributes: * task_input (dict containing email_id) * task_output (optional, dict containing total emails sent) * requester, the user who executed the task
With this information, gets the corresponding email object from the bulk emails table, and loads up a dict containing the following: * created, the time the email was sent displayed in default time display * sent_to, the group the email was delivered to * email, dict containing the subject, id, and html_message of an email * number_sent, int number of emails sent * requester, the user who sent the emails If task_input cannot be loaded, then the email cannot be loaded and None is returned for these fields.
- lms.djangoapps.instructor.views.instructor_task_helpers.extract_task_features(task)#
Convert task to dict for json rendering. Expects tasks have the following features: * task_type (str, type of task) * task_input (dict, input(s) to the task) * task_id (str, celery id of the task) * requester (str, username who submitted the task) * task_state (str, state of task eg PROGRESS, COMPLETED) * created (datetime, when the task was completed) * task_output (optional)
lms.djangoapps.instructor.views.tools module#
Tools for the instructor dashboard
- exception lms.djangoapps.instructor.views.tools.DashboardError#
Bases:
ExceptionErrors arising from use of the instructor dashboard.
- response()#
Generate an instance of HttpResponseBadRequest for this error.
- lms.djangoapps.instructor.views.tools.dump_block_extensions(course, unit)#
Dumps data about students with due date extensions for a particular block, specified by ‘url’, in a particular course.
- lms.djangoapps.instructor.views.tools.dump_student_extensions(course, student)#
Dumps data about the due date extensions granted for a particular student in a particular course.
- lms.djangoapps.instructor.views.tools.find_unit(course, url)#
Finds the unit/block with the given url in the course tree and returns the unit. Raises DashboardError if no unit is found.
- lms.djangoapps.instructor.views.tools.get_student_from_identifier(unique_student_identifier)#
Gets a student object using either an email address or username.
Returns the student object associated with unique_student_identifier
Raises User.DoesNotExist if no user object can be found, the user was retired, or the user is in the process of being retired.
DEPRECATED: use student.models.get_user_by_username_or_email instead.
- lms.djangoapps.instructor.views.tools.get_units_with_due_date(course)#
Returns all top level units which have due dates. Does not return descendents of those nodes.
- lms.djangoapps.instructor.views.tools.handle_dashboard_error(view)#
Decorator which adds seamless DashboardError handling to a view. If a DashboardError is raised during view processing, an HttpResponseBadRequest is sent back to the client with JSON data about the error.
- lms.djangoapps.instructor.views.tools.keep_field_private(query_features, field_name)#
Utility to remove a field from a list of field names requested of a report Keeps the specified field_name private (excluded from report)
- lms.djangoapps.instructor.views.tools.parse_datetime(datestr)#
Convert user input date string into an instance of datetime.datetime in UTC.
- lms.djangoapps.instructor.views.tools.require_student_from_identifier(unique_student_identifier)#
Same as get_student_from_identifier() but will raise a DashboardError if the student does not exist.
- lms.djangoapps.instructor.views.tools.set_due_date_extension(course, unit, student, due_date, actor=None, reason='')#
Sets a due date extension.
- Raises:
DashboardError if the unit or extended, due date is invalid or user is –
not enrolled in the course. –
- lms.djangoapps.instructor.views.tools.strip_if_string(value)#
- lms.djangoapps.instructor.views.tools.title_or_url(node)#
Returns the display_name attribute of the passed in node of the course tree, if it has one. Otherwise returns the node’s url.