From 0f212cc8f291847efa799c329dcc66dddac93b83 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 22 Jan 2013 12:53:20 -0500 Subject: [PATCH] Fix course id passing, template rendering --- lms/djangoapps/courseware/tabs.py | 6 +++--- .../open_ended_notifications.py | 21 ++++++++++++++----- lms/djangoapps/open_ended_grading/views.py | 11 +++++++--- lms/urls.py | 5 ++++- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 7a8367a42b..3aa502e95e 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -109,7 +109,7 @@ def _staff_grading(tab, user, course, active_page): link = reverse('staff_grading', args=[course.id]) tab_name = "Staff grading" - notifications = open_ended_notifications.staff_grading_notifications(course_id) + notifications = open_ended_notifications.staff_grading_notifications(course) pending_grading = notifications['pending_grading'] img_path = notifications['img_path'] @@ -122,7 +122,7 @@ def _peer_grading(tab, user, course, active_page): link = reverse('peer_grading', args=[course.id]) tab_name = "Peer grading" - notifications = open_ended_notifications.peer_grading_notifications(course_id, user) + notifications = open_ended_notifications.peer_grading_notifications(course, user) pending_grading = notifications['pending_grading'] img_path = notifications['img_path'] @@ -135,7 +135,7 @@ def _combined_open_ended_grading(tab, user, course, active_page): link = reverse('open_ended_problems', args=[course.id]) tab_name = "Open Ended Questions" - notifications = open_ended_notifications.combined_notifications(course_id, user) + notifications = open_ended_notifications.combined_notifications(course, user) pending_grading = notifications['pending_grading'] img_path = notifications['img_path'] diff --git a/lms/djangoapps/open_ended_grading/open_ended_notifications.py b/lms/djangoapps/open_ended_grading/open_ended_notifications.py index 516b19e326..9ab75833ca 100644 --- a/lms/djangoapps/open_ended_grading/open_ended_notifications.py +++ b/lms/djangoapps/open_ended_grading/open_ended_notifications.py @@ -6,6 +6,10 @@ import json from student.models import unique_id_for_user import open_ended_util from courseware.models import StudentModule +import logging +from courseware.access import has_access + +log=logging.getLogger(__name__) NOTIFICATION_TYPES = ( ('student_needs_to_peer_grade', 'peer_grading', 'Peer Grading'), @@ -13,10 +17,11 @@ NOTIFICATION_TYPES = ( ('overall_need_to_check', 'open_ended_problems', 'Problems you have submitted') ) -def staff_grading_notifications(course_id): +def staff_grading_notifications(course): staff_gs = StaffGradingService(settings.STAFF_GRADING_INTERFACE) pending_grading=False img_path= "" + course_id = course.id try: notifications = json.loads(staff_gs.get_notifications(course_id)) if notifications['success']: @@ -24,6 +29,7 @@ def staff_grading_notifications(course_id): pending_grading=True except: #Non catastrophic error, so no real action + notifications = {} log.info("Problem with getting notifications from staff grading service.") if pending_grading: @@ -31,10 +37,12 @@ def staff_grading_notifications(course_id): return {'pending_grading' : pending_grading, 'img_path' : img_path, 'response' : notifications} -def peer_grading_notifications(course_id, user): +def peer_grading_notifications(course, user): peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE) pending_grading=False img_path= "" + course_id = course.id + try: notifications = json.loads(peer_gs.get_notifications(course_id,unique_id_for_user(user))) if notifications['success']: @@ -42,6 +50,7 @@ def peer_grading_notifications(course_id, user): pending_grading=True except: #Non catastrophic error, so no real action + notifications = {} log.info("Problem with getting notifications from peer grading service.") if pending_grading: @@ -49,14 +58,15 @@ def peer_grading_notifications(course_id, user): return {'pending_grading' : pending_grading, 'img_path' : img_path, 'response' : notifications} -def combined_notifications(course_id, user): +def combined_notifications(course, user): controller_url = open_ended_util.get_controller_url() controller_qs = ControllerQueryService(controller_url) student_id = unique_id_for_user(user) - user_is_staff = has_access(user, course, 'staff') + user_is_staff = has_access(user, course, 'staff') + course_id = course.id min_time_to_query = user.last_login - last_module_seen = StudentModule.objects.all(student=user, course_id = course_id, modified__gt=min_time_to_query).values('modified').order_by('-modified')[0] + last_module_seen = StudentModule.objects.filter(student=user, course_id = course_id, modified__gt=min_time_to_query).values('modified').order_by('-modified')[0] last_time_viewed = last_module_seen['modified'] pending_grading= False @@ -69,6 +79,7 @@ def combined_notifications(course_id, user): pending_grading=True except: #Non catastrophic error, so no real action + notifications = {} log.info("Problem with getting notifications from controller query service.") if pending_grading: diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py index a1907ae230..c617eaac3f 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -165,10 +165,12 @@ def student_problem_list(request, course_id): @cache_control(no_cache=True, no_store=True, must_revalidate=True) def combined_notifications(request, course_id): + course = get_course_with_access(request.user, course_id, 'load') user = request.user - notifications = open_ended_notifications.combined_notifications(course_id, user) + notifications = open_ended_notifications.combined_notifications(course, user) response = notifications['response'] - notificaton_tuples=open_ended_notifications.NOTIFICATION_TYPES + notification_tuples=open_ended_notifications.NOTIFICATION_TYPES + notification_list = [] for response_num in xrange(0,len(notification_tuples)): @@ -191,8 +193,11 @@ def combined_notifications(request, course_id): combined_dict = { 'error_text' : "", 'notification_list' : notification_list, + 'course' : course, } - return combined_dict + return render_to_response('open_ended_problems/combined_notifications.html', + combined_dict + ) diff --git a/lms/urls.py b/lms/urls.py index c7c4f231f9..4b3cc94cab 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -285,7 +285,7 @@ if settings.COURSEWARE_ENABLED: # Open Ended problem list url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/open_ended_problems$', 'open_ended_grading.views.student_problem_list', name='open_ended_problems'), - + # Cohorts management url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/cohorts$', 'course_groups.views.list_cohorts', name="cohorts"), @@ -305,6 +305,9 @@ if settings.COURSEWARE_ENABLED: 'course_groups.views.debug_cohort_mgmt', name="debug_cohort_mgmt"), + # Open Ended Notifications + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/open_ended_notifications$', + 'open_ended_grading.views.combined_notifications', name='open_ended_notifications'), ) # discussion forums live within courseware, so courseware must be enabled first