From 97655d03584689d45f5ee053d6eee3a007e5efde Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Thu, 7 Feb 2013 09:40:30 -0500 Subject: [PATCH] Remove the requirement that the problem peer grading module has to have a certain naming structure --- .../xmodule/xmodule/peer_grading_module.py | 45 ++++++++++++++++++- lms/templates/peer_grading/peer_grading.html | 14 +++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 0e6beb8c74..0cb131ae9b 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -32,6 +32,7 @@ from .stringify import stringify_children from .x_module import XModule from .xml_module import XmlDescriptor from xmodule.modulestore import Location +from xmodule.modulestore.django import modulestore from timeinfo import TimeInfo from peer_grading_service import peer_grading_service, GradingServiceError @@ -109,10 +110,14 @@ class PeerGradingModule(XModule): self.max_grade = int(self.max_grade) def closed(self): - if self.timeinfo.close_date is not None and datetime.utcnow() > self.timeinfo.close_date: + return self._closed(self.timeinfo) + + def _closed(self, timeinfo): + if timeinfo.close_date is not None and datetime.utcnow() > timeinfo.close_date: return True return False + def _err_response(self, msg): """ Return a HttpResponse with a json dump with success=False, and the given error message. @@ -456,6 +461,44 @@ class PeerGradingModule(XModule): error_text = "Could not get problem list" success = False + + # grab all peer grading module descriptors for this course + peer_grading_modules = modulestore().get_items(['i4x', self.location.org, self.location.course, 'peergrading', None], self.system.course_id) + + # construct a dictionary for fast lookups + module_dict = {} + for module in peer_grading_modules: + linked_location = module.metadata.get("link_to_location", None) + if linked_location: + module_dict[linked_location] = module + + def _find_corresponding_module_for_location(location): + if location in module_dict: + return module_dict[location] + else: + return None + + for problem in problem_list: + problem_location = problem['location'] + descriptor = _find_corresponding_module_for_location(problem_location) + if descriptor: + problem['due'] = descriptor.metadata.get('due', None) + grace_period_string = descriptor.metadata.get('graceperiod', None) + try: + problem_timeinfo = TimeInfo(problem['due'], grace_period_string) + except: + log.error("Malformed due date or grace period string for location {0}".format(problem_location)) + raise + if self._closed(problem_timeinfo): + problem['closed'] = True + else: + problem['closed'] = False + else: + # if we can't find the due date, assume that it doesn't have one + problem['due'] = None + problem['closed'] = False + + ajax_url = self.ajax_url html = self.system.render_template('peer_grading/peer_grading.html', { 'course_id': self.system.course_id, diff --git a/lms/templates/peer_grading/peer_grading.html b/lms/templates/peer_grading/peer_grading.html index d309b4486c..0485b698b2 100644 --- a/lms/templates/peer_grading/peer_grading.html +++ b/lms/templates/peer_grading/peer_grading.html @@ -14,6 +14,7 @@ + @@ -22,7 +23,18 @@ %for problem in problem_list: +
Problem NameDue date Graded Available Required
- ${problem['problem_name']} + %if problem['closed']: + ${problem['problem_name']} + %else: + ${problem['problem_name']} + %endif + + % if problem['due']: + ${problem['due']} + % else: + No due date + % endif ${problem['num_graded']}