Check to see if a location is valid before displaying it for instructor grading
This commit is contained in:
@@ -15,6 +15,7 @@ from xmodule.course_module import CourseDescriptor
|
||||
from student.models import unique_id_for_user
|
||||
from xmodule.x_module import ModuleSystem
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
from utils import does_location_exist
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -240,7 +241,6 @@ def get_next(request, course_id):
|
||||
return HttpResponse(_get_next(course_id, grader_id, location),
|
||||
mimetype="application/json")
|
||||
|
||||
|
||||
def get_problem_list(request, course_id):
|
||||
"""
|
||||
Get all the problems for the given course id
|
||||
@@ -266,6 +266,15 @@ def get_problem_list(request, course_id):
|
||||
_check_access(request.user, course_id)
|
||||
try:
|
||||
response = staff_grading_service().get_problem_list(course_id, unique_id_for_user(request.user))
|
||||
response = json.loads(response)
|
||||
problem_list = response['problem_list']
|
||||
valid_problem_list = []
|
||||
for i in xrange(0,len(problem_list)):
|
||||
if does_location_exist(course_id, problem_list[i]['location']):
|
||||
valid_problem_list.append(problem_list[i])
|
||||
response['problem_list'] = valid_problem_list
|
||||
response = json.dumps(response)
|
||||
|
||||
return HttpResponse(response,
|
||||
mimetype="application/json")
|
||||
except GradingServiceError:
|
||||
|
||||
16
lms/djangoapps/open_ended_grading/utils.py
Normal file
16
lms/djangoapps/open_ended_grading/utils.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from xmodule.modulestore import search
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
def does_location_exist(course_id, location):
|
||||
"""
|
||||
Checks to see if a valid module exists at a given location (ie has not been deleted)
|
||||
course_id - string course id
|
||||
location - string location
|
||||
"""
|
||||
try:
|
||||
search.path_to_location(modulestore(), course_id, location)
|
||||
return True
|
||||
except ItemNotFoundError:
|
||||
#If the problem cannot be found at the location received from the grading controller server, it has been deleted by the course author.
|
||||
return False
|
||||
@@ -179,6 +179,7 @@ def student_problem_list(request, course_id):
|
||||
error_text = ""
|
||||
problem_list = []
|
||||
base_course_url = reverse('courses')
|
||||
list_to_remove = []
|
||||
|
||||
try:
|
||||
#Get list of all open ended problems that the grading server knows about
|
||||
@@ -192,7 +193,6 @@ def student_problem_list(request, course_id):
|
||||
problem_list = problem_list_dict['problem_list']
|
||||
|
||||
#A list of problems to remove (problems that can't be found in the course)
|
||||
list_to_remove = []
|
||||
for i in xrange(0, len(problem_list)):
|
||||
try:
|
||||
#Try to load each problem in the courseware to get links to them
|
||||
|
||||
Reference in New Issue
Block a user