Commit 6c06b39b by Calen Pennington

Centralize when json parsing of responses from controller_query_service happens

parent d0daa617
...@@ -25,7 +25,7 @@ class ControllerQueryService(GradingService): ...@@ -25,7 +25,7 @@ class ControllerQueryService(GradingService):
'location': location, 'location': location,
} }
response = self.get(self.check_eta_url, params) response = self.get(self.check_eta_url, params)
return response return response.json()
def check_combined_notifications(self, course_id, student_id, user_is_staff, last_time_viewed): def check_combined_notifications(self, course_id, student_id, user_is_staff, last_time_viewed):
params = { params = {
...@@ -36,7 +36,7 @@ class ControllerQueryService(GradingService): ...@@ -36,7 +36,7 @@ class ControllerQueryService(GradingService):
} }
log.debug(self.combined_notifications_url) log.debug(self.combined_notifications_url)
response = self.get(self.combined_notifications_url, params) response = self.get(self.combined_notifications_url, params)
return response return response.json()
def get_grading_status_list(self, course_id, student_id): def get_grading_status_list(self, course_id, student_id):
params = { params = {
...@@ -45,7 +45,7 @@ class ControllerQueryService(GradingService): ...@@ -45,7 +45,7 @@ class ControllerQueryService(GradingService):
} }
response = self.get(self.grading_status_list_url, params) response = self.get(self.grading_status_list_url, params)
return response return response.json()
def get_flagged_problem_list(self, course_id): def get_flagged_problem_list(self, course_id):
params = { params = {
...@@ -53,7 +53,7 @@ class ControllerQueryService(GradingService): ...@@ -53,7 +53,7 @@ class ControllerQueryService(GradingService):
} }
response = self.get(self.flagged_problem_list_url, params) response = self.get(self.flagged_problem_list_url, params)
return response return response.json()
def take_action_on_flags(self, course_id, student_id, submission_id, action_type): def take_action_on_flags(self, course_id, student_id, submission_id, action_type):
params = { params = {
...@@ -64,7 +64,7 @@ class ControllerQueryService(GradingService): ...@@ -64,7 +64,7 @@ class ControllerQueryService(GradingService):
} }
response = self.post(self.take_action_on_flags_url, params) response = self.post(self.take_action_on_flags_url, params)
return response return response.json()
class MockControllerQueryService(object): class MockControllerQueryService(object):
...@@ -84,15 +84,47 @@ class MockControllerQueryService(object): ...@@ -84,15 +84,47 @@ class MockControllerQueryService(object):
pass pass
def check_combined_notifications(self, *args, **kwargs): def check_combined_notifications(self, *args, **kwargs):
combined_notifications = '{"flagged_submissions_exist": false, "version": 1, "new_student_grading_to_view": false, "success": true, "staff_needs_to_grade": false, "student_needs_to_peer_grade": true, "overall_need_to_check": true}' combined_notifications = {
"flagged_submissions_exist": False,
"version": 1,
"new_student_grading_to_view": False,
"success": True,
"staff_needs_to_grade": False,
"student_needs_to_peer_grade": True,
"overall_need_to_check": True
}
return combined_notifications return combined_notifications
def get_grading_status_list(self, *args, **kwargs): def get_grading_status_list(self, *args, **kwargs):
grading_status_list = '{"version": 1, "problem_list": [{"problem_name": "Science Question -- Machine Assessed", "grader_type": "NA", "eta_available": true, "state": "Waiting to be Graded", "eta": 259200, "location": "i4x://MITx/oe101x/combinedopenended/Science_SA_ML"}, {"problem_name": "Humanities Question -- Peer Assessed", "grader_type": "NA", "eta_available": true, "state": "Waiting to be Graded", "eta": 259200, "location": "i4x://MITx/oe101x/combinedopenended/Humanities_SA_Peer"}], "success": true}' grading_status_list = {
"version": 1,
"problem_list": [
{
"problem_name": "Science Question -- Machine Assessed",
"grader_type": "NA",
"eta_available": True,
"state": "Waiting to be Graded",
"eta": 259200,
"location": "i4x://MITx/oe101x/combinedopenended/Science_SA_ML"
}, {
"problem_name": "Humanities Question -- Peer Assessed",
"grader_type": "NA",
"eta_available": True,
"state": "Waiting to be Graded",
"eta": 259200,
"location": "i4x://MITx/oe101x/combinedopenended/Humanities_SA_Peer"
}
],
"success": True
}
return grading_status_list return grading_status_list
def get_flagged_problem_list(self, *args, **kwargs): def get_flagged_problem_list(self, *args, **kwargs):
flagged_problem_list = '{"version": 1, "success": false, "error": "No flagged submissions exist for course: MITx/oe101x/2012_Fall"}' flagged_problem_list = {
"version": 1,
"success": False,
"error": "No flagged submissions exist for course: MITx/oe101x/2012_Fall"
}
return flagged_problem_list return flagged_problem_list
def take_action_on_flags(self, *args, **kwargs): def take_action_on_flags(self, *args, **kwargs):
...@@ -113,5 +145,4 @@ def convert_seconds_to_human_readable(seconds): ...@@ -113,5 +145,4 @@ def convert_seconds_to_human_readable(seconds):
else: else:
human_string = "{0} days".format(round(seconds / (60 * 60 * 24), 1)) human_string = "{0} days".format(round(seconds / (60 * 60 * 24), 1))
eta_string = "{0}".format(human_string) return human_string
return eta_string
...@@ -533,10 +533,6 @@ class OpenEndedChild(object): ...@@ -533,10 +533,6 @@ class OpenEndedChild(object):
def get_eta(self): def get_eta(self):
if self.controller_qs: if self.controller_qs:
response = self.controller_qs.check_for_eta(self.location_string) response = self.controller_qs.check_for_eta(self.location_string)
try:
response = json.loads(response)
except:
pass
else: else:
return "" return ""
......
...@@ -165,9 +165,8 @@ def combined_notifications(course, user): ...@@ -165,9 +165,8 @@ def combined_notifications(course, user):
try: try:
#Get the notifications from the grading controller #Get the notifications from the grading controller
controller_response = controller_qs.check_combined_notifications(course.id, student_id, user_is_staff, notifications = controller_qs.check_combined_notifications(course.id, student_id, user_is_staff,
last_time_viewed) last_time_viewed)
notifications = json.loads(controller_response)
if notifications.get('success'): if notifications.get('success'):
if (notifications.get('staff_needs_to_grade') or if (notifications.get('staff_needs_to_grade') or
notifications.get('student_needs_to_peer_grade')): notifications.get('student_needs_to_peer_grade')):
......
...@@ -62,10 +62,9 @@ class StudentProblemListMockQuery(object): ...@@ -62,10 +62,9 @@ class StudentProblemListMockQuery(object):
def get_grading_status_list(self, *args, **kwargs): def get_grading_status_list(self, *args, **kwargs):
""" """
Get a mock grading status list with locations from the open_ended test course. Get a mock grading status list with locations from the open_ended test course.
@returns: json formatted grading status message. @returns: grading status message dictionary.
""" """
grading_status_list = json.dumps( return {
{
"version": 1, "version": 1,
"problem_list": [ "problem_list": [
{ {
...@@ -95,8 +94,6 @@ class StudentProblemListMockQuery(object): ...@@ -95,8 +94,6 @@ class StudentProblemListMockQuery(object):
], ],
"success": True "success": True
} }
)
return grading_status_list
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
......
...@@ -118,12 +118,10 @@ class StudentProblemList(object): ...@@ -118,12 +118,10 @@ class StudentProblemList(object):
self.success = False self.success = False
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
problem_list_json = self.controller_qs.get_grading_status_list(self.course_id, self.user_id) problem_list_dict = self.controller_qs.get_grading_status_list(self.course_id, self.user_id)
except GradingServiceError: except GradingServiceError:
log.error("Problem contacting open ended grading service " + self.course_error_ending) log.error("Problem contacting open ended grading service " + self.course_error_ending)
return self.success return self.success
try:
problem_list_dict = json.loads(problem_list_json)
except ValueError: except ValueError:
log.error("Problem with results from external grading service for open ended" + self.course_error_ending) log.error("Problem with results from external grading service for open ended" + self.course_error_ending)
return self.success return self.success
......
...@@ -197,8 +197,7 @@ def flagged_problem_list(request, course_id): ...@@ -197,8 +197,7 @@ def flagged_problem_list(request, course_id):
# Make a service that can query edX ORA. # Make a service that can query edX ORA.
controller_qs = create_controller_query_service() controller_qs = create_controller_query_service()
try: try:
problem_list_json = controller_qs.get_flagged_problem_list(course_id) problem_list_dict = controller_qs.get_flagged_problem_list(course_id)
problem_list_dict = json.loads(problem_list_json)
success = problem_list_dict['success'] success = problem_list_dict['success']
if 'error' in problem_list_dict: if 'error' in problem_list_dict:
error_text = problem_list_dict['error'] error_text = problem_list_dict['error']
...@@ -326,7 +325,7 @@ def take_action_on_flags(request, course_id): ...@@ -326,7 +325,7 @@ def take_action_on_flags(request, course_id):
controller_qs = create_controller_query_service() controller_qs = create_controller_query_service()
try: try:
response = controller_qs.take_action_on_flags(course_id, student_id, submission_id, action_type) response = controller_qs.take_action_on_flags(course_id, student_id, submission_id, action_type)
return HttpResponse(response, mimetype="application/json") return HttpResponse(json.dumps(response), mimetype="application/json")
except GradingServiceError: except GradingServiceError:
log.exception( log.exception(
u"Error taking action on flagged peer grading submissions, " u"Error taking action on flagged peer grading submissions, "
......
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