Commit fcb215a6 by Sef Kloninger

Merge pull request #547 from edx/sef/peer-eval-xmodule-date-error-master

fix crash in peer eval xmodule
parents 8ae33416 02463398
...@@ -12,7 +12,7 @@ from xmodule.modulestore.django import modulestore ...@@ -12,7 +12,7 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.exceptions import ItemNotFoundError
from .timeinfo import TimeInfo from .timeinfo import TimeInfo
from xblock.core import Dict, String, Scope, Boolean, Integer, Float 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 xmodule.open_ended_grading_classes.peer_grading_service import PeerGradingService, GradingServiceError, MockPeerGradingService
from open_ended_grading_classes import combined_open_ended_rubric from open_ended_grading_classes import combined_open_ended_rubric
...@@ -47,9 +47,8 @@ class PeerGradingFields(object): ...@@ -47,9 +47,8 @@ class PeerGradingFields(object):
help="Due date that should be displayed.", help="Due date that should be displayed.",
default=None, default=None,
scope=Scope.settings) scope=Scope.settings)
grace_period_string = String( graceperiod = Timedelta(
help="Amount of grace to give on the due date.", help="Amount of grace to give on the due date.",
default=None,
scope=Scope.settings scope=Scope.settings
) )
student_data_for_location = Dict( student_data_for_location = Dict(
...@@ -105,12 +104,12 @@ class PeerGradingModule(PeerGradingFields, XModule): ...@@ -105,12 +104,12 @@ class PeerGradingModule(PeerGradingFields, XModule):
log.error("Linked location {0} for peer grading module {1} does not exist".format( log.error("Linked location {0} for peer grading module {1} does not exist".format(
self.link_to_location, self.location)) self.link_to_location, self.location))
raise raise
due_date = self.linked_problem._model_data.get('due', None) due_date = self.linked_problem.lms.due
if due_date: if due_date:
self._model_data['due'] = due_date self.lms.due = due_date
try: try:
self.timeinfo = TimeInfo(self.due, self.grace_period_string) self.timeinfo = TimeInfo(self.due, self.graceperiod)
except Exception: except Exception:
log.error("Error parsing due date information in location {0}".format(self.location)) log.error("Error parsing due date information in location {0}".format(self.location))
raise raise
...@@ -533,10 +532,10 @@ class PeerGradingModule(PeerGradingFields, XModule): ...@@ -533,10 +532,10 @@ class PeerGradingModule(PeerGradingFields, XModule):
problem_location = problem['location'] problem_location = problem['location']
descriptor = _find_corresponding_module_for_location(problem_location) descriptor = _find_corresponding_module_for_location(problem_location)
if descriptor: if descriptor:
problem['due'] = descriptor._model_data.get('due', None) problem['due'] = descriptor.lms.due
grace_period_string = descriptor._model_data.get('graceperiod', None) grace_period = descriptor.lms.graceperiod
try: try:
problem_timeinfo = TimeInfo(problem['due'], grace_period_string) problem_timeinfo = TimeInfo(problem['due'], grace_period)
except: except:
log.error("Malformed due date or grace period string for location {0}".format(problem_location)) log.error("Malformed due date or grace period string for location {0}".format(problem_location))
raise raise
...@@ -629,5 +628,5 @@ class PeerGradingDescriptor(PeerGradingFields, RawDescriptor): ...@@ -629,5 +628,5 @@ class PeerGradingDescriptor(PeerGradingFields, RawDescriptor):
@property @property
def non_editable_metadata_fields(self): def non_editable_metadata_fields(self):
non_editable_fields = super(PeerGradingDescriptor, self).non_editable_metadata_fields 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 return non_editable_fields
...@@ -14,20 +14,23 @@ class TimeInfo(object): ...@@ -14,20 +14,23 @@ class TimeInfo(object):
""" """
_delta_standin = Timedelta() _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: if due_date is not None:
self.display_due_date = due_date self.display_due_date = due_date
else: else:
self.display_due_date = None self.display_due_date = None
if grace_period_string is not None and self.display_due_date: if grace_period_string_or_timedelta is not None and self.display_due_date:
try: if isinstance(grace_period_string_or_timedelta, basestring):
self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string) try:
self.close_date = self.display_due_date + self.grace_period self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string_or_timedelta)
except: except:
log.error("Error parsing the grace period {0}".format(grace_period_string)) log.error("Error parsing the grace period {0}".format(grace_period_string_or_timedelta))
raise raise
else:
self.grace_period = grace_period_string_or_timedelta
self.close_date = self.display_due_date + self.grace_period
else: else:
self.grace_period = None self.grace_period = None
self.close_date = self.display_due_date self.close_date = self.display_due_date
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment