Commit cd49e1bb by Vik Paruchuri

Check to see if a location is valid before displaying it for instructor grading

parent c2e5c607
...@@ -15,6 +15,7 @@ from xmodule.course_module import CourseDescriptor ...@@ -15,6 +15,7 @@ from xmodule.course_module import CourseDescriptor
from student.models import unique_id_for_user from student.models import unique_id_for_user
from xmodule.x_module import ModuleSystem from xmodule.x_module import ModuleSystem
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
from utils import does_location_exist
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -240,7 +241,6 @@ def get_next(request, course_id): ...@@ -240,7 +241,6 @@ def get_next(request, course_id):
return HttpResponse(_get_next(course_id, grader_id, location), return HttpResponse(_get_next(course_id, grader_id, location),
mimetype="application/json") mimetype="application/json")
def get_problem_list(request, course_id): def get_problem_list(request, course_id):
""" """
Get all the problems for the given course id Get all the problems for the given course id
...@@ -266,6 +266,15 @@ def get_problem_list(request, course_id): ...@@ -266,6 +266,15 @@ def get_problem_list(request, course_id):
_check_access(request.user, course_id) _check_access(request.user, course_id)
try: try:
response = staff_grading_service().get_problem_list(course_id, unique_id_for_user(request.user)) 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, return HttpResponse(response,
mimetype="application/json") mimetype="application/json")
except GradingServiceError: except GradingServiceError:
......
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): ...@@ -179,6 +179,7 @@ def student_problem_list(request, course_id):
error_text = "" error_text = ""
problem_list = [] problem_list = []
base_course_url = reverse('courses') base_course_url = reverse('courses')
list_to_remove = []
try: try:
#Get list of all open ended problems that the grading server knows about #Get list of all open ended problems that the grading server knows about
...@@ -192,7 +193,6 @@ def student_problem_list(request, course_id): ...@@ -192,7 +193,6 @@ def student_problem_list(request, course_id):
problem_list = problem_list_dict['problem_list'] problem_list = problem_list_dict['problem_list']
#A list of problems to remove (problems that can't be found in the course) #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)): for i in xrange(0, len(problem_list)):
try: try:
#Try to load each problem in the courseware to get links to them #Try to load each problem in the courseware to get links to them
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment