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
01882078
Commit
01882078
authored
Oct 22, 2013
by
Alexander Kryklia
Committed by
polesye
Oct 23, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix to_json of RelativeTime to support Isotime format.
parent
040b4da1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
common/lib/xmodule/xmodule/fields.py
+9
-9
common/lib/xmodule/xmodule/tests/test_fields.py
+3
-3
No files found.
common/lib/xmodule/xmodule/fields.py
View file @
01882078
...
...
@@ -196,7 +196,7 @@ class RelativeTime(Field):
if
isinstance
(
value
,
float
):
# backward compatibility
if
value
>
86400
:
value
=
86400
return
str
(
datetime
.
timedelta
(
seconds
=
value
))
return
s
elf
.
_s
tr
(
datetime
.
timedelta
(
seconds
=
value
))
if
isinstance
(
value
,
datetime
.
timedelta
):
if
value
.
total_seconds
()
>
86400
:
# sanity check
...
...
@@ -204,18 +204,18 @@ class RelativeTime(Field):
"RelativeTime max value is 23:59:59=86400.0 seconds, "
"but {} seconds is passed"
.
format
(
value
.
total_seconds
())
)
return
str
(
value
)
return
s
elf
.
_s
tr
(
value
)
raise
TypeError
(
"RelativeTime: cannot convert {!r} to json"
.
format
(
value
))
def
_
_str__
(
self
):
def
_
str
(
self
,
value
):
"""
Makes first
H
in str representation non-optional.
Makes first
'H'
in str representation non-optional.
str(timedelta) has [H]H:MM:SS format, which is not suitable
for front-end (and IsoTime standart), so we forse HH:MM:SS
for front-end (and IsoTime standart), so we forse HH:MM:SS
format.
"""
_str
=
super
(
RelativeTime
,
slef
)
.
__str__
(
self
)
if
len
(
_str
)
==
7
:
_str
=
'0'
+
_str
return
_str
string
=
str
(
value
)
if
len
(
string
)
==
7
:
string
=
'0'
+
string
return
string
common/lib/xmodule/xmodule/tests/test_fields.py
View file @
01882078
...
...
@@ -145,7 +145,7 @@ class RelativeTimeTest(unittest.TestCase):
def
test_to_json
(
self
):
self
.
assertEqual
(
"1:02:03"
,
"
0
1:02:03"
,
RelativeTimeTest
.
delta
.
to_json
(
datetime
.
timedelta
(
seconds
=
3723
))
)
self
.
assertEqual
(
...
...
@@ -153,7 +153,7 @@ class RelativeTimeTest(unittest.TestCase):
RelativeTimeTest
.
delta
.
to_json
(
None
)
)
self
.
assertEqual
(
"0:01:40"
,
"0
0
:01:40"
,
RelativeTimeTest
.
delta
.
to_json
(
100.0
)
)
...
...
@@ -170,7 +170,7 @@ class RelativeTimeTest(unittest.TestCase):
def
test_str
(
self
):
self
.
assertEqual
(
"1:02:03"
,
"
0
1:02:03"
,
RelativeTimeTest
.
delta
.
to_json
(
datetime
.
timedelta
(
seconds
=
3723
))
)
self
.
assertEqual
(
...
...
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