Commit 482b31b9 by Syed Hassan Raza

Handle dates have year smaller than 1900

parent 614bcafb
......@@ -328,7 +328,8 @@ def _course_outline_json(request, course_module):
course_module,
include_child_info=True,
course_outline=True,
include_children_predicate=lambda xblock: not xblock.category == 'vertical'
include_children_predicate=lambda xblock: not xblock.category == 'vertical',
user=request.user
)
......
......@@ -479,6 +479,7 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None,
if verr.message:
reason = _("Invalid data ({details})").format(details=verr.message)
return JsonResponse({"error": reason}, 400)
field.write_to(xblock, value)
# update the xblock and call any xblock callbacks
......@@ -754,7 +755,8 @@ def _get_module_info(xblock, rewrite_static_links=True, include_ancestor_info=Fa
def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=False, include_child_info=False,
course_outline=False, include_children_predicate=NEVER, parent_xblock=None, graders=None):
course_outline=False, include_children_predicate=NEVER, parent_xblock=None, graders=None,
user=None):
"""
Creates the information needed for client-side XBlockInfo.
......@@ -794,6 +796,7 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
course_outline,
graders,
include_children_predicate=include_children_predicate,
user=user
)
else:
child_info = None
......@@ -832,7 +835,7 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
"published_on": get_default_time_display(xblock.published_on) if published and xblock.published_on else None,
"studio_url": xblock_studio_url(xblock, parent_xblock),
"released_to_students": datetime.now(UTC) > xblock.start,
"release_date": _get_release_date(xblock),
"release_date": _get_release_date(xblock, user),
"visibility_state": visibility_state,
"has_explicit_staff_lock": xblock.fields['visible_to_staff_only'].is_set_on(xblock),
"start": xblock.fields['start'].to_json(xblock.start),
......@@ -1003,7 +1006,7 @@ def _create_xblock_ancestor_info(xblock, course_outline):
}
def _create_xblock_child_info(xblock, course_outline, graders, include_children_predicate=NEVER):
def _create_xblock_child_info(xblock, course_outline, graders, include_children_predicate=NEVER, user=None):
"""
Returns information about the children of an xblock, as well as about the primary category
of xblock expected as children.
......@@ -1021,16 +1024,22 @@ def _create_xblock_child_info(xblock, course_outline, graders, include_children_
child, include_child_info=True, course_outline=course_outline,
include_children_predicate=include_children_predicate,
parent_xblock=xblock,
graders=graders
graders=graders,
user=user
) for child in xblock.get_children()
]
return child_info
def _get_release_date(xblock):
def _get_release_date(xblock, user=None):
"""
Returns the release date for the xblock, or None if the release date has never been set.
"""
# If year of start date is less than 1900 then reset the start date to DEFAULT_START_DATE
if xblock.start.year < 1900 and user:
xblock.start = DEFAULT_START_DATE
xblock = _update_with_callback(xblock, user)
# Treat DEFAULT_START_DATE as a magic number that means the release date has not been set
return get_default_time_display(xblock.start) if xblock.start != DEFAULT_START_DATE else None
......
......@@ -29,6 +29,7 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
from xmodule.modulestore.tests.factories import ItemFactory, LibraryFactory, check_mongo_calls, CourseFactory
from xmodule.x_module import STUDIO_VIEW, STUDENT_VIEW
from xmodule.course_module import DEFAULT_START_DATE
from xblock.exceptions import NoSuchHandlerError
from xblock_django.user_service import DjangoXBlockUserService
from opaque_keys.edx.keys import UsageKey, CourseKey
......@@ -1531,11 +1532,14 @@ class TestXBlockInfo(ItemTest):
def test_vertical_xblock_info(self):
vertical = modulestore().get_item(self.vertical.location)
vertical.start = datetime(year=1899, month=1, day=1, tzinfo=UTC)
xblock_info = create_xblock_info(
vertical,
include_child_info=True,
include_children_predicate=ALWAYS,
include_ancestor_info=True
include_ancestor_info=True,
user=self.user
)
add_container_page_publishing_info(vertical, xblock_info)
self.validate_vertical_xblock_info(xblock_info)
......@@ -1601,6 +1605,7 @@ class TestXBlockInfo(ItemTest):
self.assertEqual(xblock_info['display_name'], 'Unit 1')
self.assertTrue(xblock_info['published'])
self.assertEqual(xblock_info['edited_by'], 'testuser')
self.assertEqual(xblock_info['start'], DEFAULT_START_DATE.strftime('%Y-%m-%dT%H:%M:%SZ'))
# Validate that the correct ancestor info has been included
ancestor_info = xblock_info.get('ancestor_info', None)
......
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