Commit 7dc68f6e by Xavier Antoviaque

xblock-fields: Revert "Enforce type of the XBlocks Fields when set"

This reverts commit e08b9898.
parent 39154d24
......@@ -3,7 +3,6 @@ Mixin defining common Studio functionality
"""
import datetime
import time
from xblock.fields import Scope, Field, Integer, XBlockMixin
......@@ -21,15 +20,6 @@ class DateTuple(Field):
return list(value.timetuple())
def enforce_type(self, value):
if isinstance(value, datetime.datetime) or value is None:
return value
if isinstance(value, tuple, time.struct_time):
return self.from_json(DateTuple)
raise TypeError("Value should be datetime, a timetuple or None, not {}".format(type(value)))
class CmsBlockMixin(XBlockMixin):
"""
......
......@@ -68,7 +68,10 @@ class Date(Field):
"""
if value is None:
return None
if isinstance(value, datetime.datetime):
if isinstance(value, time.struct_time):
# struct_times are always utc
return time.strftime('%Y-%m-%dT%H:%M:%SZ', value)
elif isinstance(value, datetime.datetime):
if value.tzinfo is None or value.utcoffset().total_seconds() == 0:
# isoformat adds +00:00 rather than Z
return value.strftime('%Y-%m-%dT%H:%M:%SZ')
......@@ -77,8 +80,6 @@ class Date(Field):
else:
raise TypeError("Cannot convert {!r} to json".format(value))
enforce_type = from_json
TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?) hour(?:s?))?(\s)?((?P<minutes>\d+?) minute(?:s)?)?(\s)?((?P<seconds>\d+?) second(?:s)?)?$')
......@@ -116,15 +117,6 @@ class Timedelta(Field):
values.append("%d %s" % (cur_value, attr))
return ' '.join(values)
def enforce_type(self, value):
"""
Ensure that when set explicitly the Field is set to a timedelta
"""
if isinstance(value, datetime.timedelta) or value is None:
return value
return self.from_json(value)
class RelativeTime(Field):
"""
......@@ -227,12 +219,3 @@ class RelativeTime(Field):
if len(stringified) == 7:
stringified = '0' + stringified
return stringified
def enforce_type(self, value):
"""
Ensure that when set explicitly the Field is set to a timedelta
"""
if isinstance(value, datetime.timedelta) or value is None:
return None
return self.from_json(value)
......@@ -17,7 +17,7 @@
-e git+https://github.com/appliedsec/pygeoip.git@95e69341cebf5a6a9fbf7c4f5439d458898bdc3b#egg=pygeoip
# Our libraries:
-e git+https://github.com/edx-solutions/XBlock.git@2821f89f844f644c2091fa50bba06eb209b8f127#egg=XBlock
-e git+https://github.com/edx/XBlock.git@cfe5c37f98febd9a215d23cb206a25711056a142#egg=XBlock
-e git+https://github.com/edx/codejail.git@71f5c5616e2a73ae8cecd1ff2362774a773d3665#egg=codejail
-e git+https://github.com/edx/diff-cover.git@v0.2.9#egg=diff_cover
-e git+https://github.com/edx/js-test-tool.git@v0.1.5#egg=js_test_tool
......
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