Commit 9c93cd8d by Braden MacDonald

Fix: Display error when attempting to reset nonexistent due date extension

parent f4e02109
...@@ -47,7 +47,8 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey ...@@ -47,7 +47,8 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
from shoppingcart.models import CourseRegistrationCode, RegistrationCodeRedemption, Order, PaidCourseRegistration, Coupon from shoppingcart.models import CourseRegistrationCode, RegistrationCodeRedemption, Order, PaidCourseRegistration, Coupon
from course_modes.models import CourseMode from course_modes.models import CourseMode
from .test_tools import msk_from_problem_urlname, get_extended_due from .test_tools import msk_from_problem_urlname
from ..views.tools import get_extended_due
@common_exceptions_400 @common_exceptions_400
......
...@@ -197,7 +197,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase): ...@@ -197,7 +197,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase):
self.user = user self.user = user
self.extended_due = functools.partial( self.extended_due = functools.partial(
get_extended_due, course, student=user) tools.get_extended_due, course, student=user)
def test_set_due_date_extension(self): def test_set_due_date_extension(self):
extended = datetime.datetime(2013, 12, 25, 0, 0, tzinfo=utc) extended = datetime.datetime(2013, 12, 25, 0, 0, tzinfo=utc)
...@@ -209,7 +209,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase): ...@@ -209,7 +209,7 @@ class TestSetDueDateExtension(ModuleStoreTestCase):
extended = datetime.datetime(2013, 12, 25, 0, 0, tzinfo=utc) extended = datetime.datetime(2013, 12, 25, 0, 0, tzinfo=utc)
user = UserFactory.create() # No student modules for this user user = UserFactory.create() # No student modules for this user
tools.set_due_date_extension(self.course, self.week1, user, extended) tools.set_due_date_extension(self.course, self.week1, user, extended)
extended_due = functools.partial(get_extended_due, self.course, student=user) extended_due = functools.partial(tools.get_extended_due, self.course, student=user)
self.assertEqual(extended_due(self.week1), extended) self.assertEqual(extended_due(self.week1), extended)
self.assertEqual(extended_due(self.homework), extended) self.assertEqual(extended_due(self.homework), extended)
...@@ -224,8 +224,11 @@ class TestSetDueDateExtension(ModuleStoreTestCase): ...@@ -224,8 +224,11 @@ class TestSetDueDateExtension(ModuleStoreTestCase):
tools.set_due_date_extension(self.course, self.week3, self.user, extended) tools.set_due_date_extension(self.course, self.week3, self.user, extended)
def test_reset_due_date_extension(self): def test_reset_due_date_extension(self):
extended = datetime.datetime(2013, 12, 25, 0, 0, tzinfo=utc)
tools.set_due_date_extension(self.course, self.week1, self.user, extended)
tools.set_due_date_extension(self.course, self.week1, self.user, None) tools.set_due_date_extension(self.course, self.week1, self.user, None)
self.assertEqual(self.extended_due(self.week1), None) self.assertEqual(self.extended_due(self.week1), None)
self.assertEqual(self.extended_due(self.homework), None)
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
...@@ -341,22 +344,6 @@ class TestDataDumps(ModuleStoreTestCase): ...@@ -341,22 +344,6 @@ class TestDataDumps(ModuleStoreTestCase):
"Extended Due Date": "2013-12-25 00:00"}]) "Extended Due Date": "2013-12-25 00:00"}])
def get_extended_due(course, unit, student):
"""
Get the extended due date out of a student's state for a particular unit.
"""
student_module = StudentModule.objects.get(
student_id=student.id,
course_id=course.id,
module_state_key=unit.location
)
state = json.loads(student_module.state)
extended = state.get('extended_due', None)
if extended:
return DATE_FIELD.from_json(extended)
def msk_from_problem_urlname(course_id, urlname, block_type='problem'): def msk_from_problem_urlname(course_id, urlname, block_type='problem'):
""" """
Convert a 'problem urlname' to a module state key (db field) Convert a 'problem urlname' to a module state key (db field)
......
...@@ -159,6 +159,22 @@ def title_or_url(node): ...@@ -159,6 +159,22 @@ def title_or_url(node):
return title return title
def get_extended_due(course, unit, student):
"""
Get the extended due date out of a student's state for a particular unit.
"""
student_module = StudentModule.objects.get(
student_id=student.id,
course_id=course.id,
module_state_key=unit.location
)
state = json.loads(student_module.state)
extended = state.get('extended_due', None)
if extended:
return DATE_FIELD.from_json(extended)
def set_due_date_extension(course, unit, student, due_date): def set_due_date_extension(course, unit, student, due_date):
""" """
Sets a due date extension. Raises DashboardError if the unit or extended Sets a due date extension. Raises DashboardError if the unit or extended
...@@ -172,6 +188,10 @@ def set_due_date_extension(course, unit, student, due_date): ...@@ -172,6 +188,10 @@ def set_due_date_extension(course, unit, student, due_date):
raise DashboardError(_("Unit {0} has no due date to extend.").format(unit.location)) raise DashboardError(_("Unit {0} has no due date to extend.").format(unit.location))
if due_date < original_due_date: if due_date < original_due_date:
raise DashboardError(_("An extended due date must be later than the original due date.")) raise DashboardError(_("An extended due date must be later than the original due date."))
else:
# We are deleting a due date extension. Check that it exists:
if not get_extended_due(course, unit, student):
raise DashboardError(_("No due date extension is set for that student and unit."))
def set_due_date(node): def set_due_date(node):
""" """
......
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