From 0887383ca78d852cd90a023dc1e619235430ad03 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 21 May 2013 14:18:00 -0400 Subject: [PATCH] Don't show peer grading button unless there is a peer grading element in the course --- lms/djangoapps/open_ended_grading/views.py | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py index cb617d609d..1b7ae18029 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -89,6 +89,30 @@ def staff_grading(request, course_id): # Checked above 'staff_access': True, }) +def find_peer_grading_module(course): + #Reverse the base course url + base_course_url = reverse('courses') + found_module = False + problem_url = "" + + #Get the course id and split it + course_id_parts = course.id.split("/") + false_dict = [False, "False", "false", "FALSE"] + #TODO: This will not work with multiple runs of a course. Make it work. The last key in the Location passed + #to get_items is called revision. Is this the same as run? + #Get the peer grading modules currently in the course + items = modulestore().get_items(['i4x', None, course_id_parts[1], 'peergrading', None]) + #See if any of the modules are centralized modules (ie display info from multiple problems) + items = [i for i in items if getattr(i,"use_for_single_location", True) in false_dict] + #Get the first one + if len(items)>0: + item_location = items[0].location + #Generate a url for the first module and redirect the user to it + problem_url_parts = search.path_to_location(modulestore(), course.id, item_location) + problem_url = generate_problem_url(problem_url_parts, base_course_url) + found_module = True + + return found_module, problem_url @cache_control(no_cache=True, no_store=True, must_revalidate=True) def peer_grading(request, course_id): @@ -98,32 +122,16 @@ def peer_grading(request, course_id): #Get the current course course = get_course_with_access(request.user, course_id, 'load') - course_id_parts = course.id.split("/") - false_dict = [False, "False", "false", "FALSE"] - #Reverse the base course url - base_course_url = reverse('courses') - try: - #TODO: This will not work with multiple runs of a course. Make it work. The last key in the Location passed - #to get_items is called revision. Is this the same as run? - #Get the peer grading modules currently in the course - items = modulestore().get_items(['i4x', None, course_id_parts[1], 'peergrading', None]) - #See if any of the modules are centralized modules (ie display info from multiple problems) - items = [i for i in items if getattr(i,"use_for_single_location", True) in false_dict] - #Get the first one - item_location = items[0].location - #Generate a url for the first module and redirect the user to it - problem_url_parts = search.path_to_location(modulestore(), course.id, item_location) - problem_url = generate_problem_url(problem_url_parts, base_course_url) - - return HttpResponseRedirect(problem_url) - except: + found_module, problem_url = find_peer_grading_module(course) + if not found_module: #This is a student_facing_error error_message = "Error with initializing peer grading. Centralized module does not exist. Please contact course staff." #This is a dev_facing_error log.exception(error_message + "Current course is: {0}".format(course_id)) return HttpResponse(error_message) + return HttpResponseRedirect(problem_url) def generate_problem_url(problem_url_parts, base_course_url): """ @@ -300,7 +308,12 @@ def combined_notifications(request, course_id): 'description': description, 'alert_message': alert_message } - notification_list.append(notification_item) + if human_name == "Peer Grading": + found_module, problem_url = find_peer_grading_module(course) + if found_module: + notification_list.append(notification_item) + else: + notification_list.append(notification_item) ajax_url = _reverse_with_slash('open_ended_notifications', course_id) combined_dict = {