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
2d2913ef
Commit
2d2913ef
authored
Feb 04, 2016
by
Peter Fogg
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11426 from edx/peter-fogg/fix-date-block-format
Correctly format date block dates.
parents
21218ef9
22cb3079
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
20 deletions
+45
-20
lms/djangoapps/courseware/date_summary.py
+30
-20
lms/djangoapps/courseware/tests/test_date_summary.py
+15
-0
No files found.
lms/djangoapps/courseware/date_summary.py
View file @
2d2913ef
...
@@ -68,28 +68,9 @@ class DateSummary(object):
...
@@ -68,28 +68,9 @@ class DateSummary(object):
def
get_context
(
self
):
def
get_context
(
self
):
"""Return the template context used to render this summary block."""
"""Return the template context used to render this summary block."""
date
=
''
if
self
.
date
is
not
None
:
# Translators: relative_date is a fuzzy description of the
# time from now until absolute_date. For example,
# absolute_date might be "Jan 01, 2020", and if today were
# December 5th, 2020, relative_date would be "1 month".
locale
=
to_locale
(
get_language
())
try
:
relative_date
=
format_timedelta
(
self
.
date
-
datetime
.
now
(
pytz
.
UTC
),
locale
=
locale
)
# Babel doesn't have translations for Esperanto, so we get
# a KeyError when testing translations with
# ?preview-lang=eo. This should not happen with any other
# languages. See https://github.com/python-babel/babel/issues/107
except
KeyError
:
relative_date
=
format_timedelta
(
self
.
date
-
datetime
.
now
(
pytz
.
UTC
))
date
=
_
(
"in {relative_date} - {absolute_date}"
)
.
format
(
relative_date
=
relative_date
,
absolute_date
=
self
.
date
.
strftime
(
self
.
date_format
),
)
return
{
return
{
'title'
:
self
.
title
,
'title'
:
self
.
title
,
'date'
:
date
,
'date'
:
self
.
_format_date
()
,
'description'
:
self
.
description
,
'description'
:
self
.
description
,
'css_class'
:
self
.
css_class
,
'css_class'
:
self
.
css_class
,
'link'
:
self
.
link
,
'link'
:
self
.
link
,
...
@@ -102,6 +83,35 @@ class DateSummary(object):
...
@@ -102,6 +83,35 @@ class DateSummary(object):
"""
"""
return
render_to_string
(
'courseware/date_summary.html'
,
self
.
get_context
())
return
render_to_string
(
'courseware/date_summary.html'
,
self
.
get_context
())
def
_format_date
(
self
):
"""
Return this block's date in a human-readable format. If the date
is None, returns the empty string.
"""
if
self
.
date
is
None
:
return
''
locale
=
to_locale
(
get_language
())
delta
=
self
.
date
-
datetime
.
now
(
pytz
.
UTC
)
try
:
relative_date
=
format_timedelta
(
delta
,
locale
=
locale
)
# Babel doesn't have translations for Esperanto, so we get
# a KeyError when testing translations with
# ?preview-lang=eo. This should not happen with any other
# languages. See https://github.com/python-babel/babel/issues/107
except
KeyError
:
relative_date
=
format_timedelta
(
delta
)
date_has_passed
=
delta
.
days
<
0
# Translators: 'absolute' is a date such as "Jan 01,
# 2020". 'relative' is a fuzzy description of the time until
# 'absolute'. For example, 'absolute' might be "Jan 01, 2020",
# and if today were December 5th, 2020, 'relative' would be "1
# month".
date_format
=
_
(
"{relative} ago - {absolute}"
)
if
date_has_passed
else
_
(
"in {relative} - {absolute}"
)
return
date_format
.
format
(
relative
=
relative_date
,
absolute
=
self
.
date
.
strftime
(
self
.
date_format
),
)
@property
@property
def
is_enabled
(
self
):
def
is_enabled
(
self
):
"""
"""
...
...
lms/djangoapps/courseware/tests/test_date_summary.py
View file @
2d2913ef
...
@@ -257,3 +257,18 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
...
@@ -257,3 +257,18 @@ class CourseDateSummaryTest(SharedModuleStoreTestCase):
)
)
self
.
assertEqual
(
block
.
link_text
,
'Learn More'
)
self
.
assertEqual
(
block
.
link_text
,
'Learn More'
)
self
.
assertEqual
(
block
.
link
,
''
)
self
.
assertEqual
(
block
.
link
,
''
)
@freezegun.freeze_time
(
'2015-01-02'
)
@ddt.data
(
(
-
1
,
'1 day ago - Jan 01, 2015'
),
(
1
,
'in 1 day - Jan 03, 2015'
)
)
@ddt.unpack
def
test_render_date_string_past
(
self
,
delta
,
expected_date_string
):
self
.
setup_course_and_user
(
days_till_start
=-
10
,
verification_status
=
'denied'
,
days_till_verification_deadline
=
delta
,
)
block
=
VerificationDeadlineDate
(
self
.
course
,
self
.
user
)
self
.
assertEqual
(
block
.
get_context
()[
'date'
],
expected_date_string
)
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