def submit_rescore_problem_for_all_students(request, usage_key, only_if_higher=False): # pylint: disable=invalid-name """ Request a problem to be rescored as a background task. The problem will be rescored for all students who have accessed the particular problem in a course and have provided and checked an answer. Parameters are the `course_id` and the `problem_url`. The url must specify the location of the problem, using i4x-type notation. ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError if the problem is already being rescored, or NotImplementedError if the problem doesn't support rescoring. """ # check arguments: let exceptions return up to the caller. check_arguments_for_rescoring(usage_key) # check to see if task is already running, and reserve it otherwise task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' task_class = rescore_problem task_input, task_key = encode_problem_and_student_input(usage_key) task_input.update({'only_if_higher': only_if_higher}) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)
def get_instructor_task_history(course_id, usage_key=None, student=None, task_type=None): """ Returns a query of InstructorTask objects of historical tasks for a given course, that optionally match a particular problem, a student, and/or a task type. """ instructor_tasks = InstructorTask.objects.filter(course_id=course_id) if usage_key is not None or student is not None: _, task_key = encode_problem_and_student_input(usage_key, student) instructor_tasks = instructor_tasks.filter(task_key=task_key) if task_type is not None: instructor_tasks = instructor_tasks.filter(task_type=task_type) return instructor_tasks.order_by('-id')
def _create_entry(self, task_state=QUEUING, task_output=None, student=None): """Creates a InstructorTask entry for testing.""" task_id = str(uuid4()) progress_json = json.dumps(task_output) if task_output is not None else None task_input, task_key = encode_problem_and_student_input(self.problem_url, student) instructor_task = InstructorTaskFactory.create(course_id=TEST_COURSE_KEY, requester=self.instructor, task_input=json.dumps(task_input), task_key=task_key, task_id=task_id, task_state=task_state, task_output=progress_json) return instructor_task
def submit_rescore_problem_for_student(request, usage_key, student, only_if_higher=False): # pylint: disable=invalid-name """ Request a problem to be rescored as a background task. The problem will be rescored for the specified student only. Parameters are the `course_id`, the `problem_url`, and the `student` as a User object. The url must specify the location of the problem, using i4x-type notation. ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError if the problem is already being rescored for this student, or NotImplementedError if the problem doesn't support rescoring. """ # check arguments: let exceptions return up to the caller. check_arguments_for_rescoring(usage_key) task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' task_class = rescore_problem task_input, task_key = encode_problem_and_student_input(usage_key, student) task_input.update({'only_if_higher': only_if_higher}) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)
def submit_delete_problem_state_for_all_students(request, usage_key): # pylint: disable=invalid-name """ Request to have state deleted for a problem as a background task. The problem's state will be deleted for all students who have accessed the particular problem in a course. Parameters are the `course_id` and the `usage_key`, which must be a :class:`Location`. ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError if the particular problem's state is already being deleted. """ # check arguments: make sure that the usage_key is defined # (since that's currently typed in). If the corresponding module descriptor doesn't exist, # an exception will be raised. Let it pass up to the caller. modulestore().get_item(usage_key) task_type = 'delete_problem_state' task_class = delete_problem_state task_input, task_key = encode_problem_and_student_input(usage_key) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)
def submit_override_score(request, usage_key, student, score): """ Request a problem score override as a background task. Only applicable to individual users. The problem score will be overridden for the specified student only. Parameters are the `course_id`, the `problem_url`, the `student` as a User object, and the score override desired. The url must specify the location of the problem, using i4x-type notation. ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError if this task is already running for this student, or NotImplementedError if the problem is not a ScorableXBlock. """ check_arguments_for_overriding(usage_key, score) task_type = override_problem_score.__name__ task_class = override_problem_score task_input, task_key = encode_problem_and_student_input(usage_key, student) task_input['score'] = score return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)
def submit_rescore_problem_for_student(request, usage_key, student, only_if_higher=False): """ Request a problem to be rescored as a background task. The problem will be rescored for the specified student only. Parameters are the `course_id`, the `problem_url`, and the `student` as a User object. The url must specify the location of the problem, using i4x-type notation. ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError if the problem is already being rescored for this student, or NotImplementedError if the problem doesn't support rescoring. """ # check arguments: let exceptions return up to the caller. check_arguments_for_rescoring(usage_key) task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' task_class = rescore_problem task_input, task_key = encode_problem_and_student_input(usage_key, student) task_input.update({'only_if_higher': only_if_higher}) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)