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
ee6c3d6b
Commit
ee6c3d6b
authored
Mar 04, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make advertised_start work when it's not parseable as a date
parent
f4032cae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
25 deletions
+44
-25
common/lib/xmodule/xmodule/course_module.py
+6
-3
common/lib/xmodule/xmodule/tests/test_course_module.py
+38
-22
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
ee6c3d6b
...
@@ -481,8 +481,8 @@ class CourseDescriptor(SequenceDescriptor):
...
@@ -481,8 +481,8 @@ class CourseDescriptor(SequenceDescriptor):
@property
@property
def
sorting_score
(
self
):
def
sorting_score
(
self
):
"""
"""
Returns a
number
that can be used to sort the courses according
Returns a
tuple
that can be used to sort the courses according
the how "new"
" they are. The "newness"
" score is computed using a
the how "new"
they are. The "newness
" score is computed using a
heuristic that takes into account the announcement and
heuristic that takes into account the announcement and
(advertized) start dates of the course if available.
(advertized) start dates of the course if available.
...
@@ -510,7 +510,10 @@ class CourseDescriptor(SequenceDescriptor):
...
@@ -510,7 +510,10 @@ class CourseDescriptor(SequenceDescriptor):
announcement
=
self
.
announcement
announcement
=
self
.
announcement
if
announcement
is
not
None
:
if
announcement
is
not
None
:
announcement
=
to_datetime
(
announcement
)
announcement
=
to_datetime
(
announcement
)
start
=
self
.
advertised_start
or
to_datetime
(
self
.
start
)
if
self
.
advertised_start
is
None
or
isinstance
(
self
.
advertised_start
,
basestring
):
start
=
to_datetime
(
self
.
start
)
else
:
start
=
to_datetime
(
self
.
advertised_start
)
now
=
to_datetime
(
time
.
gmtime
())
now
=
to_datetime
(
time
.
gmtime
())
return
announcement
,
start
,
now
return
announcement
,
start
,
now
...
...
common/lib/xmodule/xmodule/tests/test_course_module.py
View file @
ee6c3d6b
...
@@ -39,7 +39,7 @@ class DummySystem(ImportSystem):
...
@@ -39,7 +39,7 @@ class DummySystem(ImportSystem):
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
"""Make sure the property is_new works on courses"""
"""Make sure the property is_new works on courses"""
@staticmethod
@staticmethod
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
):
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
):
"""Get a dummy course"""
"""Get a dummy course"""
system
=
DummySystem
(
load_error_modules
=
True
)
system
=
DummySystem
(
load_error_modules
=
True
)
...
@@ -49,48 +49,64 @@ class IsNewCourseTestCase(unittest.TestCase):
...
@@ -49,48 +49,64 @@ class IsNewCourseTestCase(unittest.TestCase):
is_new
=
to_attrb
(
'is_new'
,
is_new
)
is_new
=
to_attrb
(
'is_new'
,
is_new
)
announcement
=
to_attrb
(
'announcement'
,
announcement
)
announcement
=
to_attrb
(
'announcement'
,
announcement
)
advertised_start
=
to_attrb
(
'advertised_start'
,
advertised_start
)
start_xml
=
'''
start_xml
=
'''
<course org="{org}" course="{course}"
<course org="{org}" course="{course}"
graceperiod="1 day" url_name="test"
graceperiod="1 day" url_name="test"
start="{start}"
start="{start}"
{announcement}
{announcement}
{is_new}>
{is_new}
{advertised_start}>
<chapter url="hi" url_name="ch" display_name="CH">
<chapter url="hi" url_name="ch" display_name="CH">
<html url_name="h" display_name="H">Two houses, ...</html>
<html url_name="h" display_name="H">Two houses, ...</html>
</chapter>
</chapter>
</course>
</course>
'''
.
format
(
org
=
ORG
,
course
=
COURSE
,
start
=
start
,
is_new
=
is_new
,
'''
.
format
(
org
=
ORG
,
course
=
COURSE
,
start
=
start
,
is_new
=
is_new
,
announcement
=
announcement
)
announcement
=
announcement
,
advertised_start
=
advertised_start
)
return
system
.
process_xml
(
start_xml
)
return
system
.
process_xml
(
start_xml
)
@patch
(
'xmodule.course_module.time.gmtime'
)
@patch
(
'xmodule.course_module.time.gmtime'
)
def
test_sorting_score
(
self
,
gmtime_mock
):
def
test_sorting_score
(
self
,
gmtime_mock
):
gmtime_mock
.
return_value
=
NOW
gmtime_mock
.
return_value
=
NOW
dates
=
[(
'2012-10-01T12:00'
,
'2012-09-01T12:00'
),
# 0
(
'2012-12-01T12:00'
,
'2012-11-01T12:00'
),
# 1
day1
=
'2012-01-01T12:00'
(
'2013-02-01T12:00'
,
'2012-12-01T12:00'
),
# 2
day2
=
'2012-01-02T12:00'
(
'2013-02-01T12:00'
,
'2012-11-10T12:00'
),
# 3
(
'2013-02-01T12:00'
,
None
),
# 4
dates
=
[
(
'2013-03-01T12:00'
,
None
),
# 5
# Announce date takes priority over actual start
(
'2013-04-01T12:00'
,
None
),
# 6
# and courses announced on a later date are newer
(
'2012-11-01T12:00'
,
None
),
# 7
# than courses announced for an earlier date
(
'2012-09-01T12:00'
,
None
),
# 8
((
day1
,
day2
,
None
),
(
day1
,
day1
,
None
),
self
.
assertLess
),
(
'1990-01-01T12:00'
,
None
),
# 9
((
day1
,
day1
,
None
),
(
day2
,
day1
,
None
),
self
.
assertEqual
),
(
'2013-01-02T12:00'
,
None
),
# 10
(
'2013-01-10T12:00'
,
'2012-12-31T12:00'
),
# 11
# Announce dates take priority over advertised starts
(
'2013-01-10T12:00'
,
'2013-01-01T12:00'
),
# 12
((
day1
,
day2
,
day1
),
(
day1
,
day1
,
day1
),
self
.
assertLess
),
((
day1
,
day1
,
day2
),
(
day2
,
day1
,
day2
),
self
.
assertEqual
),
# Later start == newer course
((
day2
,
None
,
None
),
(
day1
,
None
,
None
),
self
.
assertLess
),
((
day1
,
None
,
None
),
(
day1
,
None
,
None
),
self
.
assertEqual
),
# Non-parseable advertised starts are ignored in preference
# to actual starts
((
day2
,
None
,
"Spring 2013"
),
(
day1
,
None
,
"Fall 2012"
),
self
.
assertLess
),
((
day1
,
None
,
"Spring 2013"
),
(
day1
,
None
,
"Fall 2012"
),
self
.
assertEqual
),
# Parseable advertised starts take priority over start dates
((
day1
,
None
,
day2
),
(
day1
,
None
,
day1
),
self
.
assertLess
),
((
day2
,
None
,
day2
),
(
day1
,
None
,
day2
),
self
.
assertEqual
),
]
]
data
=
[]
data
=
[]
for
i
,
d
in
enumerate
(
dates
):
for
a
,
b
,
assertion
in
dates
:
descriptor
=
self
.
get_dummy_course
(
start
=
d
[
0
],
announcement
=
d
[
1
])
a_score
=
self
.
get_dummy_course
(
start
=
a
[
0
],
announcement
=
a
[
1
],
advertised_start
=
a
[
2
])
.
sorting_score
score
=
descriptor
.
sorting_score
b_score
=
self
.
get_dummy_course
(
start
=
b
[
0
],
announcement
=
b
[
1
],
advertised_start
=
b
[
2
])
.
sorting_score
data
.
append
((
score
,
i
))
print
"Comparing
%
s to
%
s"
%
(
a
,
b
)
assertion
(
a_score
,
b_score
)
result
=
[
d
[
1
]
for
d
in
sorted
(
data
)]
assert
(
result
==
[
12
,
11
,
2
,
3
,
1
,
0
,
6
,
5
,
4
,
10
,
7
,
8
,
9
])
@patch
(
'xmodule.course_module.time.gmtime'
)
@patch
(
'xmodule.course_module.time.gmtime'
)
...
...
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