Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions lms/djangoapps/instructor/management/commands/openended_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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"
help = ("Usage: openended_post <course_id> <problem_location> <student_ids.txt> <hostname> --dry-run --task-number=<task_number>\n"
"The text file should contain a User.id in each line.")

option_list = BaseCommand.option_list + (
Expand All @@ -36,10 +36,11 @@ def handle(self, *args, **options):
dry_run = options['dry_run']
task_number = options['task_number']

if len(args) == 3:
if len(args) == 4:
course_id = args[0]
location = args[1]
students_ids = [line.strip() for line in open(args[2])]
hostname = args[3]
else:
print self.help
return
Expand All @@ -62,15 +63,20 @@ def handle(self, *args, **options):
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)
post_submission_for_student(student, course, location, task_number, dry_run=dry_run, hostname=hostname)


def post_submission_for_student(student, course, location, task_number, dry_run=True):
def post_submission_for_student(student, course, location, task_number, dry_run=True, hostname=None):
"""If the student's task child_state is ASSESSING post submission to grader."""

print "{0}:{1}".format(student.id, student.username)

request = DummyRequest()
request.user = student
request.host = hostname

try:
module = get_module_for_student(student, course, location)
module = get_module_for_student(student, course, location, request=request)
if module is None:
print " WARNING: No state found."
return False
Expand Down Expand Up @@ -104,3 +110,22 @@ def post_submission_for_student(student, course, location, task_number, dry_run=
print err

return False

class DummyRequest(object):
"""Dummy request"""

META = {}

def __init__(self):
self.session = {}
self.user = None
self.host = None
self.secure = True

def get_host(self):
"""Return a default host."""
return self.host

def is_secure(self):
"""Always secure."""
return self.secure
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner to modify the DummyRequest class in utils.py but it is used for grading too. So to keep the changes isolated I have defined a new one. I can modify the other one too instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, since it's more conservative.

7 changes: 4 additions & 3 deletions lms/djangoapps/instructor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def is_secure(self):
return False


def get_module_for_student(student, course, location):
def get_module_for_student(student, course, location, request=None):
"""Return the module for the (student, location) using a DummyRequest."""
request = DummyRequest()
request.user = student
if request is None:
request = DummyRequest()
request.user = student
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the conditional here, too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because there are other commands that use this function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that don't pass in request as a param

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not pretty, but again I just wanted to keep moving parts to a minimum for this hotfix


descriptor = modulestore().get_instance(course.id, location, depth=0)
field_data_cache = FieldDataCache([descriptor], course.id, student)
Expand Down