From 02463398195b2cc99adc13ef867df49c2e7e8e0e Mon Sep 17 00:00:00 2001 From: Sef Kloninger Date: Wed, 31 Jul 2013 13:20:29 -0700 Subject: [PATCH] fix crash in peer eval xmodule As documented in Jira LMS-806: Steps to reproduce: * as one user, for a peer evaluated problem, enter something that needs peer grading * as another user, log in and fire up the peer grading panel. You should see something that needs attention, a yellow exclamation badge * clicking on the "do grading" panel will fail with a 500, stacktrace attached. * it's possible that the question where this is being done must first have professor calibration done in order for peers to be able to actually get work to grade. Don Mitchell debugged this with me and saw some problems in the ways that the peer_evaluation xmodule code was accessing dates. Instead of using the normal lms accessors, by going straight into the _module_data it would be bypassing some important code (caching?). Fixing this to be more standard did the trick. --- .../xmodule/xmodule/peer_grading_module.py | 19 +++++++++---------- common/lib/xmodule/xmodule/timeinfo.py | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 09cac9a6b4..05883ce8c0 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -12,7 +12,7 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError from .timeinfo import TimeInfo from xblock.core import Dict, String, Scope, Boolean, Integer, Float -from xmodule.fields import Date +from xmodule.fields import Date, Timedelta from xmodule.open_ended_grading_classes.peer_grading_service import PeerGradingService, GradingServiceError, MockPeerGradingService from open_ended_grading_classes import combined_open_ended_rubric @@ -47,9 +47,8 @@ class PeerGradingFields(object): help="Due date that should be displayed.", default=None, scope=Scope.settings) - grace_period_string = String( + graceperiod = Timedelta( help="Amount of grace to give on the due date.", - default=None, scope=Scope.settings ) student_data_for_location = Dict( @@ -105,12 +104,12 @@ class PeerGradingModule(PeerGradingFields, XModule): log.error("Linked location {0} for peer grading module {1} does not exist".format( self.link_to_location, self.location)) raise - due_date = self.linked_problem._model_data.get('due', None) + due_date = self.linked_problem.lms.due if due_date: - self._model_data['due'] = due_date + self.lms.due = due_date try: - self.timeinfo = TimeInfo(self.due, self.grace_period_string) + self.timeinfo = TimeInfo(self.due, self.graceperiod) except Exception: log.error("Error parsing due date information in location {0}".format(self.location)) raise @@ -533,10 +532,10 @@ class PeerGradingModule(PeerGradingFields, XModule): problem_location = problem['location'] descriptor = _find_corresponding_module_for_location(problem_location) if descriptor: - problem['due'] = descriptor._model_data.get('due', None) - grace_period_string = descriptor._model_data.get('graceperiod', None) + problem['due'] = descriptor.lms.due + grace_period = descriptor.lms.graceperiod try: - problem_timeinfo = TimeInfo(problem['due'], grace_period_string) + problem_timeinfo = TimeInfo(problem['due'], grace_period) except: log.error("Malformed due date or grace period string for location {0}".format(problem_location)) raise @@ -629,5 +628,5 @@ class PeerGradingDescriptor(PeerGradingFields, RawDescriptor): @property def non_editable_metadata_fields(self): non_editable_fields = super(PeerGradingDescriptor, self).non_editable_metadata_fields - non_editable_fields.extend([PeerGradingFields.due, PeerGradingFields.grace_period_string]) + non_editable_fields.extend([PeerGradingFields.due, PeerGradingFields.graceperiod]) return non_editable_fields diff --git a/common/lib/xmodule/xmodule/timeinfo.py b/common/lib/xmodule/xmodule/timeinfo.py index 8f4d99506a..76f24a0b23 100644 --- a/common/lib/xmodule/xmodule/timeinfo.py +++ b/common/lib/xmodule/xmodule/timeinfo.py @@ -14,20 +14,23 @@ class TimeInfo(object): """ _delta_standin = Timedelta() - def __init__(self, due_date, grace_period_string): + def __init__(self, due_date, grace_period_string_or_timedelta): if due_date is not None: self.display_due_date = due_date else: self.display_due_date = None - if grace_period_string is not None and self.display_due_date: - try: - self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string) - self.close_date = self.display_due_date + self.grace_period - except: - log.error("Error parsing the grace period {0}".format(grace_period_string)) - raise + if grace_period_string_or_timedelta is not None and self.display_due_date: + if isinstance(grace_period_string_or_timedelta, basestring): + try: + self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string_or_timedelta) + except: + log.error("Error parsing the grace period {0}".format(grace_period_string_or_timedelta)) + raise + else: + self.grace_period = grace_period_string_or_timedelta + self.close_date = self.display_due_date + self.grace_period else: self.grace_period = None self.close_date = self.display_due_date