Clean up names and refactor out some common logic
This commit is contained in:
@@ -26,6 +26,18 @@ if settings.MOCK_PEER_GRADING:
|
||||
else:
|
||||
peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE)
|
||||
|
||||
"""
|
||||
Reverses the URL from the name and the course id, and then adds a trailing slash if
|
||||
it does not exist yet
|
||||
|
||||
"""
|
||||
def _reverse_with_slash(url_name, course_id):
|
||||
ajax_url = reverse(url_name, kwargs={'course_id': course_id})
|
||||
if not ajax_url.endswith('/'):
|
||||
ajax_url += '/'
|
||||
return ajax_url
|
||||
|
||||
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
def staff_grading(request, course_id):
|
||||
"""
|
||||
@@ -33,9 +45,7 @@ def staff_grading(request, course_id):
|
||||
"""
|
||||
course = get_course_with_access(request.user, course_id, 'staff')
|
||||
|
||||
ajax_url = reverse('staff_grading', kwargs={'course_id': course_id})
|
||||
if not ajax_url.endswith('/'):
|
||||
ajax_url += '/'
|
||||
ajax_url = _reverse_with_slash('staff_grading', course_id)
|
||||
|
||||
return render_to_response('instructor/staff_grading.html', {
|
||||
'course': course,
|
||||
@@ -57,24 +67,23 @@ def peer_grading(request, course_id):
|
||||
error_text = ""
|
||||
problem_list = []
|
||||
try:
|
||||
problem_list_text = peer_gs.get_problem_list(course_id, unique_id_for_user(request.user))
|
||||
problem_list_json = json.loads(problem_list_text)
|
||||
success = problem_list_json['success']
|
||||
if 'error' in problem_list_json:
|
||||
error_text = problem_list_json['error']
|
||||
problem_list_json = peer_gs.get_problem_list(course_id, unique_id_for_user(request.user))
|
||||
problem_list_dict = json.loads(problem_list_json)
|
||||
success = problem_list_dict['success']
|
||||
if 'error' in problem_list_dict:
|
||||
error_text = problem_list_dict['error']
|
||||
|
||||
problem_list = problem_list_json['problem_list']
|
||||
problem_list = problem_list_dict['problem_list']
|
||||
|
||||
except GradingServiceError:
|
||||
error_text = "Error occured while contacting the grading service"
|
||||
success = False
|
||||
# catch error if if the json loads fails
|
||||
except ValueError:
|
||||
error_text = "Could not get problem list"
|
||||
success = False
|
||||
|
||||
ajax_url = reverse('peer_grading', kwargs={'course_id': course_id})
|
||||
if not ajax_url.endswith('/'):
|
||||
ajax_url += '/'
|
||||
ajax_url = _reverse_with_slash('peer_grading', course_id)
|
||||
|
||||
return render_to_response('peer_grading/peer_grading.html', {
|
||||
'course': course,
|
||||
@@ -95,9 +104,7 @@ def peer_grading_problem(request, course_id):
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
problem_location = request.GET.get("location")
|
||||
|
||||
ajax_url = reverse('peer_grading', kwargs={'course_id': course_id})
|
||||
if not ajax_url.endswith('/'):
|
||||
ajax_url += '/'
|
||||
ajax_url = _reverse_with_slash('peer_grading', course_id)
|
||||
|
||||
return render_to_response('peer_grading/peer_grading_problem.html', {
|
||||
'view_html': '',
|
||||
|
||||
Reference in New Issue
Block a user