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
68716f99
Commit
68716f99
authored
May 31, 2013
by
Vasyl Nakvasiuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
video module: `_get_timeframe` -> `get_timeframe`
parent
b2571034
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
25 deletions
+34
-25
common/lib/xmodule/xmodule/video_module.py
+31
-22
lms/djangoapps/courseware/tests/test_video_xml.py
+3
-3
No files found.
common/lib/xmodule/xmodule/video_module.py
View file @
68716f99
"""Video is ungraded Xmodule for support video content."""
import
json
import
json
import
logging
import
logging
...
@@ -8,7 +10,6 @@ from django.http import Http404
...
@@ -8,7 +10,6 @@ from django.http import Http404
from
xmodule.x_module
import
XModule
from
xmodule.x_module
import
XModule
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.contentstore.content
import
StaticContent
from
xblock.core
import
Integer
,
Scope
,
String
from
xblock.core
import
Integer
,
Scope
,
String
import
datetime
import
datetime
...
@@ -18,21 +19,26 @@ log = logging.getLogger(__name__)
...
@@ -18,21 +19,26 @@ log = logging.getLogger(__name__)
class
VideoFields
(
object
):
class
VideoFields
(
object
):
"""Fields for `VideoModule` and `VideoDescriptor`."""
data
=
String
(
help
=
"XML data for the problem"
,
scope
=
Scope
.
content
)
data
=
String
(
help
=
"XML data for the problem"
,
scope
=
Scope
.
content
)
position
=
Integer
(
help
=
"Current position in the video"
,
scope
=
Scope
.
user_state
,
default
=
0
)
position
=
Integer
(
help
=
"Current position in the video"
,
scope
=
Scope
.
user_state
,
default
=
0
)
class
VideoModule
(
VideoFields
,
XModule
):
class
VideoModule
(
VideoFields
,
XModule
):
"""Video Xmodule."""
video_time
=
0
video_time
=
0
icon_class
=
'video'
icon_class
=
'video'
js
=
{
'coffee'
:
js
=
{
[
resource_string
(
__name__
,
'js/src/time.coffee'
),
'coffee'
:
[
resource_string
(
__name__
,
'js/src/video/display.coffee'
)]
+
resource_string
(
__name__
,
'js/src/time.coffee'
),
resource_string
(
__name__
,
'js/src/video/display.coffee'
)
]
+
[
resource_string
(
__name__
,
'js/src/video/display/'
+
filename
)
[
resource_string
(
__name__
,
'js/src/video/display/'
+
filename
)
for
filename
for
filename
in
sorted
(
resource_listdir
(
__name__
,
'js/src/video/display'
))
in
sorted
(
resource_listdir
(
__name__
,
'js/src/video/display'
))
if
filename
.
endswith
(
'.coffee'
)]}
if
filename
.
endswith
(
'.coffee'
)]
}
css
=
{
'scss'
:
[
resource_string
(
__name__
,
'css/video/display.scss'
)]}
css
=
{
'scss'
:
[
resource_string
(
__name__
,
'css/video/display.scss'
)]}
js_module_name
=
"Video"
js_module_name
=
"Video"
...
@@ -44,14 +50,14 @@ class VideoModule(VideoFields, XModule):
...
@@ -44,14 +50,14 @@ class VideoModule(VideoFields, XModule):
self
.
show_captions
=
xmltree
.
get
(
'show_captions'
,
'true'
)
self
.
show_captions
=
xmltree
.
get
(
'show_captions'
,
'true'
)
self
.
source
=
self
.
_get_source
(
xmltree
)
self
.
source
=
self
.
_get_source
(
xmltree
)
self
.
track
=
self
.
_get_track
(
xmltree
)
self
.
track
=
self
.
_get_track
(
xmltree
)
self
.
start_time
,
self
.
end_time
=
self
.
_
get_timeframe
(
xmltree
)
self
.
start_time
,
self
.
end_time
=
self
.
get_timeframe
(
xmltree
)
def
_get_source
(
self
,
xmltree
):
def
_get_source
(
self
,
xmltree
):
# find the first valid source
"""Find the first valid source."""
return
self
.
_get_first_external
(
xmltree
,
'source'
)
return
self
.
_get_first_external
(
xmltree
,
'source'
)
def
_get_track
(
self
,
xmltree
):
def
_get_track
(
self
,
xmltree
):
# find the first valid track
"""Find the first valid track."""
return
self
.
_get_first_external
(
xmltree
,
'track'
)
return
self
.
_get_first_external
(
xmltree
,
'track'
)
def
_get_first_external
(
self
,
xmltree
,
tag
):
def
_get_first_external
(
self
,
xmltree
,
tag
):
...
@@ -68,29 +74,30 @@ class VideoModule(VideoFields, XModule):
...
@@ -68,29 +74,30 @@ class VideoModule(VideoFields, XModule):
break
break
return
result
return
result
def
_
get_timeframe
(
self
,
xmltree
):
def
get_timeframe
(
self
,
xmltree
):
""" Converts 'from' and 'to' parameters in video tag to seconds.
""" Converts 'from' and 'to' parameters in video tag to seconds.
If there are no parameters, returns empty string. """
If there are no parameters, returns empty string. """
def
parse_time
(
s
):
def
parse_time
(
s
tr_time
):
"""Converts s in '12:34:45' format to seconds. If s is
"""Converts s in '12:34:45' format to seconds. If s is
None, returns empty string"""
None, returns empty string"""
if
s
is
None
:
if
s
tr_time
is
None
:
return
''
return
''
else
:
else
:
x
=
time
.
strptime
(
s
,
'
%
H:
%
M:
%
S'
)
obj_time
=
time
.
strptime
(
str_time
,
'
%
H:
%
M:
%
S'
)
return
datetime
.
timedelta
(
hours
=
x
.
tm_hour
,
return
datetime
.
timedelta
(
minutes
=
x
.
tm_min
,
hours
=
obj_time
.
tm_hour
,
seconds
=
x
.
tm_sec
)
.
total_seconds
()
minutes
=
obj_time
.
tm_min
,
seconds
=
obj_time
.
tm_sec
)
.
total_seconds
()
return
parse_time
(
xmltree
.
get
(
'from'
)),
parse_time
(
xmltree
.
get
(
'to'
))
return
parse_time
(
xmltree
.
get
(
'from'
)),
parse_time
(
xmltree
.
get
(
'to'
))
def
handle_ajax
(
self
,
dispatch
,
get
):
def
handle_ajax
(
self
,
dispatch
,
get
):
'''
"""Handle ajax calls to this video.
Handle ajax calls to this video.
TODO (vshnayder): This is not being called right now, so the position
TODO (vshnayder): This is not being called right now, so the position
is not being saved.
is not being saved.
'''
"""
log
.
debug
(
u"GET {0}"
.
format
(
get
))
log
.
debug
(
u"GET {0}"
.
format
(
get
))
log
.
debug
(
u"DISPATCH {0}"
.
format
(
dispatch
))
log
.
debug
(
u"DISPATCH {0}"
.
format
(
dispatch
))
if
dispatch
==
'goto_position'
:
if
dispatch
==
'goto_position'
:
...
@@ -100,27 +107,28 @@ class VideoModule(VideoFields, XModule):
...
@@ -100,27 +107,28 @@ class VideoModule(VideoFields, XModule):
raise
Http404
()
raise
Http404
()
def
get_progress
(
self
):
def
get_progress
(
self
):
'''
TODO (vshnayder): Get and save duration of youtube video, then return
"""
TODO (vshnayder): Get and save duration of youtube video, then return
fraction watched.
fraction watched.
(Be careful to notice when video link changes and update)
(Be careful to notice when video link changes and update)
For now, we have no way of knowing if the video has even been watched, so
For now, we have no way of knowing if the video has even been watched, so
just return None.
just return None.
'''
"""
return
None
return
None
def
get_instance_state
(
self
):
def
get_instance_state
(
self
):
#log.debug(u"STATE POSITION {0}".format(self.position))
"""Return information about state (position)."""
return
json
.
dumps
({
'position'
:
self
.
position
})
return
json
.
dumps
({
'position'
:
self
.
position
})
def
video_list
(
self
):
def
video_list
(
self
):
"""Return video list."""
return
self
.
youtube
return
self
.
youtube
def
get_html
(
self
):
def
get_html
(
self
):
# We normally let JS parse this, but in the case that we need a hacked
# We normally let JS parse this, but in the case that we need a hacked
# out <object> player because YouTube has broken their <iframe> API for
# out <object> player because YouTube has broken their <iframe> API for
# the third time in a year, we need to extract it server side.
# the third time in a year, we need to extract it server side.
normal_speed_video_id
=
None
# The 1.0 speed video
normal_speed_video_id
=
None
# The 1.0 speed video
# video_list() example:
# video_list() example:
# "0.75:nugHYNiD3fI,1.0:7m8pab1MfYY,1.25:3CxdPGXShq8,1.50:F-D7bOFCnXA"
# "0.75:nugHYNiD3fI,1.0:7m8pab1MfYY,1.25:3CxdPGXShq8,1.50:F-D7bOFCnXA"
...
@@ -144,6 +152,7 @@ class VideoModule(VideoFields, XModule):
...
@@ -144,6 +152,7 @@ class VideoModule(VideoFields, XModule):
class
VideoDescriptor
(
VideoFields
,
RawDescriptor
):
class
VideoDescriptor
(
VideoFields
,
RawDescriptor
):
"""Descriptor for `VideoModule`."""
module_class
=
VideoModule
module_class
=
VideoModule
stores_state
=
True
stores_state
=
True
template_dir_name
=
"video"
template_dir_name
=
"video"
lms/djangoapps/courseware/tests/test_video_xml.py
View file @
68716f99
...
@@ -70,7 +70,7 @@ class VideoModuleLogicTest(LogicTest):
...
@@ -70,7 +70,7 @@ class VideoModuleLogicTest(LogicTest):
def
test_get_timeframe_no_parameters
(
self
):
def
test_get_timeframe_no_parameters
(
self
):
"""Make sure that timeframe() works correctly w/o parameters"""
"""Make sure that timeframe() works correctly w/o parameters"""
xmltree
=
etree
.
fromstring
(
'<video>test</video>'
)
xmltree
=
etree
.
fromstring
(
'<video>test</video>'
)
output
=
self
.
xmodule
.
_
get_timeframe
(
xmltree
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
''
,
''
))
self
.
assertEqual
(
output
,
(
''
,
''
))
def
test_get_timeframe_with_one_parameter
(
self
):
def
test_get_timeframe_with_one_parameter
(
self
):
...
@@ -78,7 +78,7 @@ class VideoModuleLogicTest(LogicTest):
...
@@ -78,7 +78,7 @@ class VideoModuleLogicTest(LogicTest):
xmltree
=
etree
.
fromstring
(
xmltree
=
etree
.
fromstring
(
'<video from="00:04:07">test</video>'
'<video from="00:04:07">test</video>'
)
)
output
=
self
.
xmodule
.
_
get_timeframe
(
xmltree
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
247
,
''
))
self
.
assertEqual
(
output
,
(
247
,
''
))
def
test_get_timeframe_with_two_parameters
(
self
):
def
test_get_timeframe_with_two_parameters
(
self
):
...
@@ -89,7 +89,7 @@ class VideoModuleLogicTest(LogicTest):
...
@@ -89,7 +89,7 @@ class VideoModuleLogicTest(LogicTest):
to="13:04:39"
to="13:04:39"
>test</video>'''
>test</video>'''
)
)
output
=
self
.
xmodule
.
_
get_timeframe
(
xmltree
)
output
=
self
.
xmodule
.
get_timeframe
(
xmltree
)
self
.
assertEqual
(
output
,
(
247
,
47079
))
self
.
assertEqual
(
output
,
(
247
,
47079
))
...
...
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