Commit 2c90fd18 by Alexander Kryklia Committed by polesye

Rename IsoTime to RelativeTime.

parent ece4cb66
...@@ -108,7 +108,7 @@ define(["backbone"], function(Backbone) { ...@@ -108,7 +108,7 @@ define(["backbone"], function(Backbone) {
Metadata.GENERIC_TYPE = "Generic"; Metadata.GENERIC_TYPE = "Generic";
Metadata.LIST_TYPE = "List"; Metadata.LIST_TYPE = "List";
Metadata.VIDEO_LIST_TYPE = "VideoList"; Metadata.VIDEO_LIST_TYPE = "VideoList";
Metadata.ISO_TIME_TYPE = "IsoTime"; Metadata.RELATIVE_TIME_TYPE = "RelativeTime";
return Metadata; return Metadata;
}); });
...@@ -38,8 +38,9 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) { ...@@ -38,8 +38,9 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {
} }
else if(model.getType() === MetadataModel.VIDEO_LIST_TYPE) { else if(model.getType() === MetadataModel.VIDEO_LIST_TYPE) {
new VideoList(data); new VideoList(data);
else if(model.getType() === MetadataModel.ISO_TIME_TYPE) { }
new Metadata.IsoTime(data); else if(model.getType() === MetadataModel.RELATIVE_TIME_TYPE) {
new Metadata.RelativeTime(data);
} }
else { else {
// Everything else is treated as GENERIC_TYPE, which uses String editor. // Everything else is treated as GENERIC_TYPE, which uses String editor.
...@@ -293,7 +294,7 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) { ...@@ -293,7 +294,7 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {
} }
}); });
Metadata.IsoTime = Metadata.AbstractEditor.extend({ Metadata.RelativeTime = AbstractEditor.extend({
events : { events : {
"change input" : "updateModel", "change input" : "updateModel",
...@@ -304,7 +305,7 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) { ...@@ -304,7 +305,7 @@ function(Backbone, _, MetadataModel, AbstractEditor, VideoList) {
templateName: "metadata-string-entry", templateName: "metadata-string-entry",
initialize: function () { initialize: function () {
Metadata.AbstractEditor.prototype.initialize.apply(this); AbstractEditor.prototype.initialize.apply(this);
// This list of definitions is used for creating appropriate // This list of definitions is used for creating appropriate
// time format mask; // time format mask;
......
...@@ -118,7 +118,7 @@ class Timedelta(Field): ...@@ -118,7 +118,7 @@ class Timedelta(Field):
return ' '.join(values) return ' '.join(values)
class IsoTime(Field): class RelativeTime(Field):
""" """
Field for start_time and end_time video module properties. Field for start_time and end_time video module properties.
...@@ -134,8 +134,8 @@ class IsoTime(Field): ...@@ -134,8 +134,8 @@ class IsoTime(Field):
In database we previously had float type for start_time and end_time fields, In database we previously had float type for start_time and end_time fields,
so we are checking it also. so we are checking it also.
Python object of IsoTime is datetime.timedelta. Python object of RelativeTime is datetime.timedelta.
JSONed representation of IsoTime is "HH:MM:SS" JSONed representation of RelativeTime is "HH:MM:SS"
""" """
# Timedeltas are immutable, see http://docs.python.org/2/library/datetime.html#available-types # Timedeltas are immutable, see http://docs.python.org/2/library/datetime.html#available-types
MUTABLE = False MUTABLE = False
...@@ -151,7 +151,7 @@ class IsoTime(Field): ...@@ -151,7 +151,7 @@ class IsoTime(Field):
obj_time = time.strptime(value, '%H:%M:%S') obj_time = time.strptime(value, '%H:%M:%S')
except ValueError as e: except ValueError as e:
raise ValueError( raise ValueError(
"Incorrect IsoTime value {} was set in XML or serialized." "Incorrect RelativeTime value {} was set in XML or serialized."
"Original parse message is {}".format(value, e.message) "Original parse message is {}".format(value, e.message)
) )
return datetime.timedelta( return datetime.timedelta(
...@@ -177,7 +177,7 @@ class IsoTime(Field): ...@@ -177,7 +177,7 @@ class IsoTime(Field):
if isinstance(value, basestring): if isinstance(value, basestring):
return self._isotime_to_timedelta(value) return self._isotime_to_timedelta(value)
msg = "IsoTime Field {0} has bad value '{1}'".format(self._name, value) msg = "RelativeTime Field {0} has bad value '{1}'".format(self._name, value)
raise TypeError(msg) raise TypeError(msg)
def to_json(self, value): def to_json(self, value):
...@@ -201,9 +201,9 @@ class IsoTime(Field): ...@@ -201,9 +201,9 @@ class IsoTime(Field):
if isinstance(value, datetime.timedelta): if isinstance(value, datetime.timedelta):
if value.total_seconds() > 86400: # sanity check if value.total_seconds() > 86400: # sanity check
raise ValueError( raise ValueError(
"IsoTime max value is 23:59:59=86400.0 seconds, " "RelativeTime max value is 23:59:59=86400.0 seconds, "
"but {} seconds is passed".format(value.total_seconds()) "but {} seconds is passed".format(value.total_seconds())
) )
return str(value) return str(value)
raise TypeError("IsoTime: cannot convert {!r} to json".format(value)) raise TypeError("RelativeTime: cannot convert {!r} to json".format(value))
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import datetime import datetime
import unittest import unittest
from django.utils.timezone import UTC from django.utils.timezone import UTC
from xmodule.fields import Date, Timedelta, IsoTime from xmodule.fields import Date, Timedelta, RelativeTime
from xmodule.timeinfo import TimeInfo from xmodule.timeinfo import TimeInfo
import time import time
...@@ -118,52 +118,52 @@ class TimeInfoTest(unittest.TestCase): ...@@ -118,52 +118,52 @@ class TimeInfoTest(unittest.TestCase):
due_date + Timedelta().from_json(grace_pd_string)) due_date + Timedelta().from_json(grace_pd_string))
class IsoTimeTest(unittest.TestCase): class RelativeTimeTest(unittest.TestCase):
delta = IsoTime() delta = RelativeTime()
def test_from_json(self): def test_from_json(self):
self.assertEqual( self.assertEqual(
IsoTimeTest.delta.from_json('0:05:07'), RelativeTimeTest.delta.from_json('0:05:07'),
datetime.timedelta(seconds=307) datetime.timedelta(seconds=307)
) )
self.assertEqual( self.assertEqual(
IsoTimeTest.delta.from_json(100.0), RelativeTimeTest.delta.from_json(100.0),
datetime.timedelta(seconds=100) datetime.timedelta(seconds=100)
) )
self.assertEqual( self.assertEqual(
IsoTimeTest.delta.from_json(None), RelativeTimeTest.delta.from_json(None),
datetime.timedelta(seconds=0) datetime.timedelta(seconds=0)
) )
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
IsoTimeTest.delta.from_json(1234) # int RelativeTimeTest.delta.from_json(1234) # int
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
IsoTimeTest.delta.from_json("77:77:77") RelativeTimeTest.delta.from_json("77:77:77")
def test_to_json(self): def test_to_json(self):
self.assertEqual( self.assertEqual(
"1:02:03", "1:02:03",
IsoTimeTest.delta.to_json(datetime.timedelta(seconds=3723)) RelativeTimeTest.delta.to_json(datetime.timedelta(seconds=3723))
) )
self.assertEqual( self.assertEqual(
"00:00:00", "00:00:00",
IsoTimeTest.delta.to_json(None) RelativeTimeTest.delta.to_json(None)
) )
self.assertEqual( self.assertEqual(
"0:01:40", "0:01:40",
IsoTimeTest.delta.to_json(100.0) RelativeTimeTest.delta.to_json(100.0)
) )
with self.assertRaises(ValueError) as cm: with self.assertRaises(ValueError) as cm:
IsoTimeTest.delta.to_json(datetime.timedelta(seconds=90000)) RelativeTimeTest.delta.to_json(datetime.timedelta(seconds=90000))
self.assertEqual( self.assertEqual(
cm.exception.message, cm.exception.message,
"IsoTime max value is 23:59:59=86400.0 seconds, but 90000.0 seconds is passed" "RelativeTime max value is 23:59:59=86400.0 seconds, but 90000.0 seconds is passed"
) )
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
IsoTimeTest.delta.to_json("123") RelativeTimeTest.delta.to_json("123")
...@@ -10,7 +10,7 @@ from xblock.field_data import DictFieldData ...@@ -10,7 +10,7 @@ from xblock.field_data import DictFieldData
from xblock.fields import Scope, String, Dict, Boolean, Integer, Float, Any, List from xblock.fields import Scope, String, Dict, Boolean, Integer, Float, Any, List
from xblock.runtime import DbModel from xblock.runtime import DbModel
from xmodule.fields import Date, Timedelta, IsoTime from xmodule.fields import Date, Timedelta, RelativeTime
from xmodule.modulestore.inheritance import InheritanceKeyValueStore, InheritanceMixin from xmodule.modulestore.inheritance import InheritanceKeyValueStore, InheritanceMixin
from xmodule.xml_module import XmlDescriptor, serialize_field, deserialize_field from xmodule.xml_module import XmlDescriptor, serialize_field, deserialize_field
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
...@@ -389,10 +389,10 @@ class TestDeserializeTimedelta(TestDeserialize): ...@@ -389,10 +389,10 @@ class TestDeserializeTimedelta(TestDeserialize):
self.assertDeserializeNonString() self.assertDeserializeNonString()
class TestDeserializeIsoTime(TestDeserialize): class TestDeserializeRelativeTime(TestDeserialize):
""" Tests deserialize as related to Timedelta type. """ """ Tests deserialize as related to Timedelta type. """
test_field = IsoTime test_field = RelativeTime
def test_deserialize(self): def test_deserialize(self):
""" """
......
...@@ -29,7 +29,7 @@ from xmodule.raw_module import EmptyDataRawDescriptor ...@@ -29,7 +29,7 @@ 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, List, Integer, ScopeIds from xblock.fields import Scope, String, Boolean, List, Integer, ScopeIds
from xmodule.fields import IsoTime from xmodule.fields import RelativeTime
from xmodule.modulestore.inheritance import InheritanceKeyValueStore from xmodule.modulestore.inheritance import InheritanceKeyValueStore
from xblock.runtime import DbModel from xblock.runtime import DbModel
...@@ -80,13 +80,13 @@ class VideoFields(object): ...@@ -80,13 +80,13 @@ class VideoFields(object):
scope=Scope.settings, scope=Scope.settings,
default="" default=""
) )
start_time = IsoTime( # datetime.timedelta object start_time = RelativeTime( # datetime.timedelta object
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=datetime.timedelta(seconds=0) default=datetime.timedelta(seconds=0)
) )
end_time = IsoTime( # datetime.timedelta object end_time = RelativeTime( # datetime.timedelta object
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,
......
...@@ -13,7 +13,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, InsufficientSpecif ...@@ -13,7 +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 xmodule.fields import RelativeTime
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
...@@ -709,8 +709,8 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock): ...@@ -709,8 +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): elif isinstance(field, RelativeTime):
editor_type = "IsoTime" editor_type = "RelativeTime"
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment