-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Django command to post submissions to ora #2001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
lms/djangoapps/instructor/management/commands/openended_post.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """ | ||
| Command to manually re-post open ended submissions to the grader. | ||
| """ | ||
| from django.contrib.auth.models import User | ||
| from django.core.management.base import BaseCommand | ||
| from optparse import make_option | ||
|
|
||
| from xmodule.modulestore.django import modulestore | ||
| from xmodule.open_ended_grading_classes.openendedchild import OpenEndedChild | ||
| from xmodule.open_ended_grading_classes.open_ended_module import OpenEndedModule | ||
|
|
||
| from courseware.courses import get_course | ||
|
|
||
| from instructor.utils import get_module_for_student | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """ | ||
| Command to manually re-post open ended submissions to the grader. | ||
| """ | ||
|
|
||
| help = ("Usage: openended_post <course_id> <problem_location> <student_ids.txt> --dry-run --task-number=<task_number>\n" | ||
| "The text file should contain a User.id in each line.") | ||
|
|
||
| option_list = BaseCommand.option_list + ( | ||
| make_option('-n', '--dry-run', | ||
| action='store_true', dest='dry_run', default=False, | ||
| help="Do everything except send the submission to the grader. "), | ||
| make_option('--task-number', | ||
| type='int', default=0, | ||
| help="Task number that needs to be submitted."), | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
|
|
||
| dry_run = options['dry_run'] | ||
| task_number = options['task_number'] | ||
|
|
||
| if len(args) == 3: | ||
| course_id = args[0] | ||
| location = args[1] | ||
| students_ids = [line.strip() for line in open(args[2])] | ||
| else: | ||
| print self.help | ||
| return | ||
|
|
||
| try: | ||
| course = get_course(course_id) | ||
| except ValueError as err: | ||
| print err | ||
| return | ||
|
|
||
| descriptor = modulestore().get_instance(course.id, location, depth=0) | ||
| if descriptor is None: | ||
| print "Location not found in course" | ||
| return | ||
|
|
||
| if dry_run: | ||
| print "Doing a dry run." | ||
|
|
||
| students = User.objects.filter(id__in=students_ids).order_by('username') | ||
| print "Number of students: {0}".format(students.count()) | ||
|
|
||
| for student in students: | ||
| post_submission_for_student(student, course, location, task_number, dry_run=dry_run) | ||
|
|
||
|
|
||
| def post_submission_for_student(student, course, location, task_number, dry_run=True): | ||
| """If the student's task child_state is ASSESSING post submission to grader.""" | ||
|
|
||
| print "{0}:{1}".format(student.id, student.username) | ||
| try: | ||
| module = get_module_for_student(student, course, location) | ||
| if module is None: | ||
| print " WARNING: No state found." | ||
| return False | ||
|
|
||
| latest_task = module.child_module.get_task_number(task_number) | ||
| if latest_task is None: | ||
| print " WARNING: No task state found." | ||
| return False | ||
|
|
||
| if not isinstance(latest_task, OpenEndedModule): | ||
| print " ERROR: Not an OpenEndedModule task." | ||
| return False | ||
|
|
||
| latest_task_state = latest_task.child_state | ||
|
|
||
| if latest_task_state == OpenEndedChild.INITIAL: | ||
| print " WARNING: No submission." | ||
| elif latest_task_state == OpenEndedChild.POST_ASSESSMENT or latest_task_state == OpenEndedChild.DONE: | ||
| print " WARNING: Submission already graded." | ||
| elif latest_task_state == OpenEndedChild.ASSESSING: | ||
| latest_answer = latest_task.latest_answer() | ||
| if dry_run: | ||
| print " Skipped sending submission to grader: {0!r}".format(latest_answer[:100].encode('utf-8')) | ||
| else: | ||
| latest_task.send_to_grader(latest_answer, latest_task.system) | ||
| print " Sent submission to grader: {0!r}".format(latest_answer[:100].encode('utf-8')) | ||
| return True | ||
| else: | ||
| print "WARNING: Invalid task_state: {0}".format(latest_task_state) | ||
| except Exception as err: # pylint: disable=broad-except | ||
| print err | ||
|
|
||
| return False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpennington I have replaced
get_current_taskwithget_task_at_index(task_index)andtask_indexcan be specified as an argument to the commands. This will ensure that for multi-step problems the commands only operate on the intended step.