From 4ffa00b4009d9014a94a92bff58b16a5f56704ad Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Mon, 14 Jan 2013 15:00:13 -0500 Subject: [PATCH 1/5] Add in notifications, peer grading tab, tab image --- lms/djangoapps/courseware/tabs.py | 34 ++++++++++++++++++- .../peer_grading_service.py | 6 ++++ .../courseware/course_navigation.html | 7 +++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 45b4e1821c..1f13db0064 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -11,6 +11,7 @@ actually generates the CourseTab. from collections import namedtuple import logging +import json from django.conf import settings from django.core.urlresolvers import reverse @@ -20,6 +21,9 @@ from fs.errors import ResourceNotFoundError from courseware.access import has_access from static_replace import replace_urls +from open_ended_grading.peer_grading_service import PeerGradingService +from student.models import unique_id_for_user + log = logging.getLogger(__name__) class InvalidTabsException(Exception): @@ -28,7 +32,10 @@ class InvalidTabsException(Exception): """ pass -CourseTab = namedtuple('CourseTab', 'name link is_active') +CourseTabBase = namedtuple('CourseTab', 'name link is_active has_img img') + +def CourseTab(name, link, is_active, has_img=False, img=""): + return CourseTabBase(name, link, is_active, has_img, img) # encapsulate implementation for a tab: # - a validation function: takes the config dict and raises @@ -104,6 +111,30 @@ def _staff_grading(tab, user, course, active_page): return [CourseTab('Staff grading', link, active_page == "staff_grading")] return [] +def _peer_grading(tab, user, course, active_page): + link = reverse('peer_grading', args=[course.id]) + peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE) + pending_grading=False + try: + notifications = json.loads(peer_gs.get_notifications(course.id,unique_id_for_user(user))) + log.debug(notifications) + + if notifications['success']: + if notifications['student_needs_to_peer_grade']: + pending_grading=True + except: + #Non catastrophic error, so no real action + log.info("Problem with getting notifications from peer grading service.") + + if pending_grading: + tab_name = "Peer grading (Pending)" + img_path = "/static/images/unanswered-icon.png" + else: + tab_name = "Peer Grading" + img_path= "" + + tab = [CourseTab(tab_name, link, active_page == "peer_grading", True, img_path)] + return tab #### Validators @@ -141,6 +172,7 @@ VALID_TAB_TYPES = { 'progress': TabImpl(need_name, _progress), 'static_tab': TabImpl(key_checker(['name', 'url_slug']), _static_tab), 'staff_grading': TabImpl(null_validator, _staff_grading), + 'peer_grading': TabImpl(null_validator, _peer_grading), } diff --git a/lms/djangoapps/open_ended_grading/peer_grading_service.py b/lms/djangoapps/open_ended_grading/peer_grading_service.py index 9ef0383fb5..8e0f8cbbaa 100644 --- a/lms/djangoapps/open_ended_grading/peer_grading_service.py +++ b/lms/djangoapps/open_ended_grading/peer_grading_service.py @@ -79,6 +79,7 @@ class PeerGradingService(GradingService): self.show_calibration_essay_url = self.url + '/show_calibration_essay/' self.save_calibration_essay_url = self.url + '/save_calibration_essay/' self.get_problem_list_url = self.url + '/get_problem_list/' + self.get_notifications_url = self.url + '/get_notifications/' def get_next_submission(self, problem_location, grader_id): response = self.get(self.get_next_submission_url, @@ -116,6 +117,11 @@ class PeerGradingService(GradingService): response = self.get(self.get_problem_list_url, params) return response + def get_notifications(self, course_id, grader_id): + params = {'course_id': course_id, 'student_id': grader_id} + response = self.get(self.get_notifications_url, params) + return response + _service = None def peer_grading_service(): diff --git a/lms/templates/courseware/course_navigation.html b/lms/templates/courseware/course_navigation.html index 5ae69908fb..ec9004c0e8 100644 --- a/lms/templates/courseware/course_navigation.html +++ b/lms/templates/courseware/course_navigation.html @@ -18,7 +18,12 @@ def url_class(is_active):
    % for tab in get_course_tabs(user, course, active_page):
  1. - ${tab.name | h} + + ${tab.name | h} + % if tab.has_img == True: + + %endif +
  2. % endfor <%block name="extratabs" /> From cc56e4763383fdfd1a1590335a074ab43656ec1d Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Mon, 14 Jan 2013 15:12:54 -0500 Subject: [PATCH 2/5] Fix active page issue --- lms/djangoapps/courseware/tabs.py | 8 ++++---- lms/templates/peer_grading/peer_grading.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 1f13db0064..139a527a42 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -127,10 +127,10 @@ def _peer_grading(tab, user, course, active_page): log.info("Problem with getting notifications from peer grading service.") if pending_grading: - tab_name = "Peer grading (Pending)" - img_path = "/static/images/unanswered-icon.png" + tab_name = "Peer grading" + img_path = "/static/images/slider-handle.png" else: - tab_name = "Peer Grading" + tab_name = "Peer grading" img_path= "" tab = [CourseTab(tab_name, link, active_page == "peer_grading", True, img_path)] @@ -171,8 +171,8 @@ VALID_TAB_TYPES = { 'textbooks': TabImpl(null_validator, _textbooks), 'progress': TabImpl(need_name, _progress), 'static_tab': TabImpl(key_checker(['name', 'url_slug']), _static_tab), - 'staff_grading': TabImpl(null_validator, _staff_grading), 'peer_grading': TabImpl(null_validator, _peer_grading), + 'staff_grading': TabImpl(null_validator, _staff_grading), } diff --git a/lms/templates/peer_grading/peer_grading.html b/lms/templates/peer_grading/peer_grading.html index 484bb94182..2eb33cae05 100644 --- a/lms/templates/peer_grading/peer_grading.html +++ b/lms/templates/peer_grading/peer_grading.html @@ -8,7 +8,7 @@ <%block name="title">${course.number} Peer Grading -<%include file="/courseware/course_navigation.html" args="active_page='staff_grading'" /> +<%include file="/courseware/course_navigation.html" args="active_page='peer_grading'" /> <%block name="js_extra"> <%static:js group='peer_grading'/> From 4353c4ab056680067809b96804e6b052bfe7dbba Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Mon, 14 Jan 2013 15:16:06 -0500 Subject: [PATCH 3/5] Clean up some logic --- lms/djangoapps/courseware/tabs.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 139a527a42..18d6612cc6 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -115,6 +115,8 @@ def _peer_grading(tab, user, course, active_page): link = reverse('peer_grading', args=[course.id]) peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE) pending_grading=False + tab_name = "Peer grading" + img_path= "" try: notifications = json.loads(peer_gs.get_notifications(course.id,unique_id_for_user(user))) log.debug(notifications) @@ -127,11 +129,7 @@ def _peer_grading(tab, user, course, active_page): log.info("Problem with getting notifications from peer grading service.") if pending_grading: - tab_name = "Peer grading" img_path = "/static/images/slider-handle.png" - else: - tab_name = "Peer grading" - img_path= "" tab = [CourseTab(tab_name, link, active_page == "peer_grading", True, img_path)] return tab From 7b1262f667e0328fbd2e5d9b5a2be6c679fc2f1e Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 15 Jan 2013 14:31:02 -0500 Subject: [PATCH 4/5] Fix up authentication, other things --- lms/djangoapps/courseware/tabs.py | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 18d6612cc6..eac059afff 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -112,27 +112,29 @@ def _staff_grading(tab, user, course, active_page): return [] def _peer_grading(tab, user, course, active_page): - link = reverse('peer_grading', args=[course.id]) - peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE) - pending_grading=False - tab_name = "Peer grading" - img_path= "" - try: - notifications = json.loads(peer_gs.get_notifications(course.id,unique_id_for_user(user))) - log.debug(notifications) + if user.is_authenticated(): + link = reverse('peer_grading', args=[course.id]) + peer_gs = PeerGradingService(settings.PEER_GRADING_INTERFACE) + pending_grading=False + tab_name = "Peer grading" + img_path= "" + try: + notifications = json.loads(peer_gs.get_notifications(course.id,unique_id_for_user(user))) + log.debug(notifications) - if notifications['success']: - if notifications['student_needs_to_peer_grade']: - pending_grading=True - except: - #Non catastrophic error, so no real action - log.info("Problem with getting notifications from peer grading service.") + if notifications['success']: + if notifications['student_needs_to_peer_grade']: + pending_grading=True + except: + #Non catastrophic error, so no real action + log.info("Problem with getting notifications from peer grading service.") - if pending_grading: - img_path = "/static/images/slider-handle.png" + if pending_grading: + img_path = "/static/images/slider-handle.png" - tab = [CourseTab(tab_name, link, active_page == "peer_grading", True, img_path)] - return tab + tab = [CourseTab(tab_name, link, active_page == "peer_grading", pending_grading, img_path)] + return tab + return [] #### Validators From 301293f8b0ec80018ac74b2c2e5484a715d415c5 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 15 Jan 2013 14:33:38 -0500 Subject: [PATCH 5/5] Remove debug statement, fix active page issue on problem page --- lms/djangoapps/courseware/tabs.py | 2 -- lms/templates/peer_grading/peer_grading_problem.html | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index eac059afff..36b11d9795 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -120,8 +120,6 @@ def _peer_grading(tab, user, course, active_page): img_path= "" try: notifications = json.loads(peer_gs.get_notifications(course.id,unique_id_for_user(user))) - log.debug(notifications) - if notifications['success']: if notifications['student_needs_to_peer_grade']: pending_grading=True diff --git a/lms/templates/peer_grading/peer_grading_problem.html b/lms/templates/peer_grading/peer_grading_problem.html index d493e84ace..9f23c0f0b1 100644 --- a/lms/templates/peer_grading/peer_grading_problem.html +++ b/lms/templates/peer_grading/peer_grading_problem.html @@ -9,7 +9,7 @@ <%block name="title">${course.number} Peer Grading. -<%include file="/courseware/course_navigation.html" args="active_page='staff_grading'" /> +<%include file="/courseware/course_navigation.html" args="active_page='peer_grading'" /> <%block name="js_extra"> <%static:js group='peer_grading'/>