Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7b1bcc32
Commit
7b1bcc32
authored
Jul 08, 2015
by
Syed Hassan Raza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start-date-reset-to-DEFAULT_START_DATE
parent
cb3140e9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
cms/djangoapps/contentstore/views/item.py
+12
-2
cms/djangoapps/contentstore/views/tests/test_item.py
+23
-2
No files found.
cms/djangoapps/contentstore/views/item.py
View file @
7b1bcc32
...
@@ -801,6 +801,8 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
...
@@ -801,6 +801,8 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
else
:
else
:
child_info
=
None
child_info
=
None
release_date
=
_get_release_date
(
xblock
,
user
)
if
xblock
.
category
!=
'course'
:
if
xblock
.
category
!=
'course'
:
visibility_state
=
_compute_visibility_state
(
xblock
,
child_info
,
is_xblock_unit
and
has_changes
)
visibility_state
=
_compute_visibility_state
(
xblock
,
child_info
,
is_xblock_unit
and
has_changes
)
else
:
else
:
...
@@ -835,7 +837,7 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
...
@@ -835,7 +837,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
,
"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
),
"studio_url"
:
xblock_studio_url
(
xblock
,
parent_xblock
),
"released_to_students"
:
datetime
.
now
(
UTC
)
>
xblock
.
start
,
"released_to_students"
:
datetime
.
now
(
UTC
)
>
xblock
.
start
,
"release_date"
:
_get_release_date
(
xblock
,
user
)
,
"release_date"
:
release_date
,
"visibility_state"
:
visibility_state
,
"visibility_state"
:
visibility_state
,
"has_explicit_staff_lock"
:
xblock
.
fields
[
'visible_to_staff_only'
]
.
is_set_on
(
xblock
),
"has_explicit_staff_lock"
:
xblock
.
fields
[
'visible_to_staff_only'
]
.
is_set_on
(
xblock
),
"start"
:
xblock
.
fields
[
'start'
]
.
to_json
(
xblock
.
start
),
"start"
:
xblock
.
fields
[
'start'
]
.
to_json
(
xblock
.
start
),
...
@@ -1036,7 +1038,15 @@ def _get_release_date(xblock, user=None):
...
@@ -1036,7 +1038,15 @@ def _get_release_date(xblock, user=None):
Returns the release date for the xblock, or None if the release date has never been set.
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 year of start date is less than 1900 then reset the start date to DEFAULT_START_DATE
if
xblock
.
start
.
year
<
1900
and
user
:
reset_to_default
=
False
try
:
reset_to_default
=
xblock
.
start
.
year
<
1900
except
ValueError
:
# For old mongo courses, accessing the start attribute calls `to_json()`,
# which raises a `ValueError` for years < 1900.
reset_to_default
=
True
if
reset_to_default
and
user
:
xblock
.
start
=
DEFAULT_START_DATE
xblock
.
start
=
DEFAULT_START_DATE
xblock
=
_update_with_callback
(
xblock
,
user
)
xblock
=
_update_with_callback
(
xblock
,
user
)
...
...
cms/djangoapps/contentstore/views/tests/test_item.py
View file @
7b1bcc32
...
@@ -1532,7 +1532,6 @@ class TestXBlockInfo(ItemTest):
...
@@ -1532,7 +1532,6 @@ class TestXBlockInfo(ItemTest):
def
test_vertical_xblock_info
(
self
):
def
test_vertical_xblock_info
(
self
):
vertical
=
modulestore
()
.
get_item
(
self
.
vertical
.
location
)
vertical
=
modulestore
()
.
get_item
(
self
.
vertical
.
location
)
vertical
.
start
=
datetime
(
year
=
1899
,
month
=
1
,
day
=
1
,
tzinfo
=
UTC
)
xblock_info
=
create_xblock_info
(
xblock_info
=
create_xblock_info
(
vertical
,
vertical
,
...
@@ -1553,6 +1552,29 @@ class TestXBlockInfo(ItemTest):
...
@@ -1553,6 +1552,29 @@ class TestXBlockInfo(ItemTest):
)
)
self
.
validate_component_xblock_info
(
xblock_info
)
self
.
validate_component_xblock_info
(
xblock_info
)
@ddt.data
(
ModuleStoreEnum
.
Type
.
split
,
ModuleStoreEnum
.
Type
.
mongo
)
def
test_validate_start_date
(
self
,
store_type
):
"""
Validate if start-date year is less than 1900 reset the date to DEFAULT_START_DATE.
"""
with
self
.
store
.
default_store
(
store_type
):
course
=
CourseFactory
.
create
()
chapter
=
ItemFactory
.
create
(
parent_location
=
course
.
location
,
category
=
'chapter'
,
display_name
=
'Week 1'
)
chapter
.
start
=
datetime
(
year
=
1899
,
month
=
1
,
day
=
1
,
tzinfo
=
UTC
)
xblock_info
=
create_xblock_info
(
chapter
,
include_child_info
=
True
,
include_children_predicate
=
ALWAYS
,
include_ancestor_info
=
True
,
user
=
self
.
user
)
self
.
assertEqual
(
xblock_info
[
'start'
],
DEFAULT_START_DATE
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
))
def
validate_course_xblock_info
(
self
,
xblock_info
,
has_child_info
=
True
,
course_outline
=
False
):
def
validate_course_xblock_info
(
self
,
xblock_info
,
has_child_info
=
True
,
course_outline
=
False
):
"""
"""
Validate that the xblock info is correct for the test course.
Validate that the xblock info is correct for the test course.
...
@@ -1605,7 +1627,6 @@ class TestXBlockInfo(ItemTest):
...
@@ -1605,7 +1627,6 @@ class TestXBlockInfo(ItemTest):
self
.
assertEqual
(
xblock_info
[
'display_name'
],
'Unit 1'
)
self
.
assertEqual
(
xblock_info
[
'display_name'
],
'Unit 1'
)
self
.
assertTrue
(
xblock_info
[
'published'
])
self
.
assertTrue
(
xblock_info
[
'published'
])
self
.
assertEqual
(
xblock_info
[
'edited_by'
],
'testuser'
)
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
# Validate that the correct ancestor info has been included
ancestor_info
=
xblock_info
.
get
(
'ancestor_info'
,
None
)
ancestor_info
=
xblock_info
.
get
(
'ancestor_info'
,
None
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment