PLAT-1890 Fixed assorted ModifyingEnforceTypeWarning warnings
This commit is contained in:
@@ -190,8 +190,8 @@ class CapaFields(object):
|
||||
# enforce_type is set to False here because this field is saved as a dict in the database.
|
||||
score = ScoreField(help=_("Dictionary with the current student score"), scope=Scope.user_state, enforce_type=False)
|
||||
has_saved_answers = Boolean(help=_("Whether or not the answers have been saved since last submit"),
|
||||
scope=Scope.user_state)
|
||||
done = Boolean(help=_("Whether the student has answered the problem"), scope=Scope.user_state)
|
||||
scope=Scope.user_state, default=False)
|
||||
done = Boolean(help=_("Whether the student has answered the problem"), scope=Scope.user_state, default=False)
|
||||
seed = Integer(help=_("Random seed for this student"), scope=Scope.user_state)
|
||||
last_submission_time = Date(help=_("Last submission time"), scope=Scope.user_state)
|
||||
submission_wait_seconds = Integer(
|
||||
|
||||
@@ -58,7 +58,7 @@ TOY_BLOCK_INFO_TREE = [
|
||||
),
|
||||
BlockInfo(
|
||||
"toyjumpto", "html", {
|
||||
"data": "<a href=\"/jump_to_id/vertical_test\">This is a link to another page and some Chinese 四節比分和七年前</a> <p>Some more Chinese 四節比分和七年前</p>\n",
|
||||
"data": u"<a href=\"/jump_to_id/vertical_test\">This is a link to another page and some Chinese 四節比分和七年前</a> <p>Some more Chinese 四節比分和七年前</p>\n",
|
||||
"xml_attributes": {"filename": ["html/toyjumpto.xml", "html/toyjumpto.xml"]}
|
||||
}, []),
|
||||
BlockInfo(
|
||||
@@ -120,7 +120,7 @@ TOY_BLOCK_INFO_TREE = [
|
||||
"poll_test", "chapter", {}, [
|
||||
BlockInfo(
|
||||
"T1_changemind_poll_foo", "poll_question", {
|
||||
"question": "<p>Have you changed your mind? ’</p>",
|
||||
"question": u"<p>Have you changed your mind? ’</p>",
|
||||
"answers": [{"text": "Yes", "id": "yes"}, {"text": "No", "id": "no"}],
|
||||
"xml_attributes": {"reset": "false", "filename": ["", None]},
|
||||
"display_name": "Change your answer"
|
||||
@@ -168,7 +168,7 @@ TOY_BLOCK_INFO_TREE = [
|
||||
}, []),
|
||||
]),
|
||||
BlockInfo("unicode", "html", {
|
||||
"data": "…", "xml_attributes": {"filename": ["", None]}
|
||||
"data": u"…", "xml_attributes": {"filename": ["", None]}
|
||||
}, [])
|
||||
]),
|
||||
]
|
||||
|
||||
@@ -793,7 +793,7 @@ class VideoExportTestCase(VideoDescriptorTestBase):
|
||||
"""
|
||||
Test XML export handles the unicode characters.
|
||||
"""
|
||||
self.descriptor.display_name = '这是文'
|
||||
self.descriptor.display_name = u'这是文'
|
||||
xml = self.descriptor.definition_to_xml(None)
|
||||
self.assertEqual(xml.get('display_name'), u'\u8fd9\u662f\u6587')
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
from datetime import datetime
|
||||
import six
|
||||
from django.utils.timezone import now
|
||||
from webob import Response
|
||||
|
||||
from xblock.core import XBlock
|
||||
@@ -40,6 +41,17 @@ log = logging.getLogger(__name__)
|
||||
# Disable no-member warning:
|
||||
# pylint: disable=no-member
|
||||
|
||||
def to_boolean(value):
|
||||
"""
|
||||
Convert a value from a GET or POST request parameter to a bool
|
||||
"""
|
||||
if isinstance(value, six.binary_type):
|
||||
value = value.decode('ascii', errors='replace')
|
||||
if isinstance(value, six.text_type):
|
||||
return value.lower() == 'true'
|
||||
else:
|
||||
return bool(value)
|
||||
|
||||
|
||||
class VideoStudentViewHandlers(object):
|
||||
"""
|
||||
@@ -61,6 +73,8 @@ class VideoStudentViewHandlers(object):
|
||||
'auto_advance': json.loads,
|
||||
'saved_video_position': RelativeTime.isotime_to_timedelta,
|
||||
'youtube_is_available': json.loads,
|
||||
'bumper_last_view_date': to_boolean,
|
||||
'bumper_do_not_show_again': to_boolean,
|
||||
}
|
||||
|
||||
if dispatch == 'save_user_state':
|
||||
@@ -72,7 +86,7 @@ class VideoStudentViewHandlers(object):
|
||||
value = data[key]
|
||||
|
||||
if key == 'bumper_last_view_date':
|
||||
value = datetime.utcnow()
|
||||
value = now()
|
||||
|
||||
setattr(self, key, value)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user