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
7cbdac73
Commit
7cbdac73
authored
Oct 07, 2013
by
polesye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new python field.
parent
6511dad1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
common/lib/xmodule/xmodule/fields.py
+14
-1
common/lib/xmodule/xmodule/video_module.py
+5
-13
common/lib/xmodule/xmodule/x_module.py
+3
-0
No files found.
common/lib/xmodule/xmodule/fields.py
View file @
7cbdac73
...
@@ -2,7 +2,7 @@ import time
...
@@ -2,7 +2,7 @@ import time
import
logging
import
logging
import
re
import
re
from
xblock.fields
import
Field
from
xblock.fields
import
Field
,
String
import
datetime
import
datetime
import
dateutil.parser
import
dateutil.parser
...
@@ -116,3 +116,16 @@ class Timedelta(Field):
...
@@ -116,3 +116,16 @@ class Timedelta(Field):
if
cur_value
>
0
:
if
cur_value
>
0
:
values
.
append
(
"
%
d
%
s"
%
(
cur_value
,
attr
))
values
.
append
(
"
%
d
%
s"
%
(
cur_value
,
attr
))
return
' '
.
join
(
values
)
return
' '
.
join
(
values
)
class
IsoTime
(
String
):
def
from_json
(
self
,
value
):
if
isinstance
(
value
,
float
):
if
not
value
:
return
"00:00:00"
else
:
return
str
(
datetime
.
timedelta
(
seconds
=
value
))
else
:
return
super
(
IsoTime
,
self
)
.
from_json
(
value
)
common/lib/xmodule/xmodule/video_module.py
View file @
7cbdac73
...
@@ -28,13 +28,15 @@ from xmodule.editing_module import TabsEditingDescriptor
...
@@ -28,13 +28,15 @@ from xmodule.editing_module import TabsEditingDescriptor
from
xmodule.raw_module
import
EmptyDataRawDescriptor
from
xmodule.raw_module
import
EmptyDataRawDescriptor
from
xmodule.xml_module
import
is_pointer_tag
,
name_to_pathname
,
deserialize_field
from
xmodule.xml_module
import
is_pointer_tag
,
name_to_pathname
,
deserialize_field
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xblock.fields
import
Scope
,
String
,
Boolean
,
Float
,
List
,
Integer
,
ScopeIds
from
xblock.fields
import
Scope
,
String
,
Boolean
,
List
,
Integer
,
ScopeIds
from
xmodule.fields
import
IsoTime
from
xmodule.modulestore.inheritance
import
InheritanceKeyValueStore
from
xmodule.modulestore.inheritance
import
InheritanceKeyValueStore
from
xblock.runtime
import
DbModel
from
xblock.runtime
import
DbModel
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
def
parse_time_from_str_to_float
(
str_time
):
def
parse_time_from_str_to_float
(
str_time
):
"""
"""
Converts s in '12:34:45' format to seconds.
Converts s in '12:34:45' format to seconds.
...
@@ -62,16 +64,6 @@ def parse_time_from_float_to_str(s):
...
@@ -62,16 +64,6 @@ def parse_time_from_float_to_str(s):
else
:
else
:
return
str
(
datetime
.
timedelta
(
seconds
=
s
))
return
str
(
datetime
.
timedelta
(
seconds
=
s
))
class
StringThatWasFloat
(
String
):
def
from_json
(
self
,
value
):
if
isinstance
(
value
,
float
):
return
parse_time_from_float_to_str
(
value
)
else
:
return
super
(
StringThatWasFloat
,
self
)
.
from_json
(
value
)
class
VideoFields
(
object
):
class
VideoFields
(
object
):
"""Fields for `VideoModule` and `VideoDescriptor`."""
"""Fields for `VideoModule` and `VideoDescriptor`."""
display_name
=
String
(
display_name
=
String
(
...
@@ -116,13 +108,13 @@ class VideoFields(object):
...
@@ -116,13 +108,13 @@ class VideoFields(object):
scope
=
Scope
.
settings
,
scope
=
Scope
.
settings
,
default
=
""
default
=
""
)
)
start_time
=
StringThatWasFloat
(
start_time
=
IsoTime
(
help
=
"Start time for the video."
,
help
=
"Start time for the video."
,
display_name
=
"Start Time"
,
display_name
=
"Start Time"
,
scope
=
Scope
.
settings
,
scope
=
Scope
.
settings
,
default
=
"00:00:00"
default
=
"00:00:00"
)
)
end_time
=
StringThatWasFloat
(
end_time
=
IsoTime
(
help
=
"End time for the video."
,
help
=
"End time for the video."
,
display_name
=
"End Time"
,
display_name
=
"End Time"
,
scope
=
Scope
.
settings
,
scope
=
Scope
.
settings
,
...
...
common/lib/xmodule/xmodule/x_module.py
View file @
7cbdac73
...
@@ -13,6 +13,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, InsufficientSpecif
...
@@ -13,6 +13,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, InsufficientSpecif
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
Integer
,
Float
,
List
,
XBlockMixin
,
String
from
xblock.fields
import
Scope
,
Integer
,
Float
,
List
,
XBlockMixin
,
String
from
xmodule.fields
import
IsoTime
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
from
xblock.runtime
import
Runtime
from
xblock.runtime
import
Runtime
from
xmodule.errortracker
import
exc_info_to_str
from
xmodule.errortracker
import
exc_info_to_str
...
@@ -708,6 +709,8 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
...
@@ -708,6 +709,8 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
editor_type
=
"Float"
editor_type
=
"Float"
elif
isinstance
(
field
,
List
):
elif
isinstance
(
field
,
List
):
editor_type
=
"List"
editor_type
=
"List"
elif
isinstance
(
field
,
IsoTime
):
editor_type
=
"IsoTime"
metadata_fields
[
field
.
name
][
'type'
]
=
editor_type
metadata_fields
[
field
.
name
][
'type'
]
=
editor_type
metadata_fields
[
field
.
name
][
'options'
]
=
[]
if
values
is
None
else
values
metadata_fields
[
field
.
name
][
'options'
]
=
[]
if
values
is
None
else
values
...
...
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