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
53a40166
Commit
53a40166
authored
Nov 14, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utility method for converting string to bool.
parent
a170c6f4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
cms/djangoapps/contentstore/views/item.py
+4
-3
common/djangoapps/util/string_utils.py
+15
-0
common/djangoapps/util/tests/test_string_utils.py
+26
-0
No files found.
cms/djangoapps/contentstore/views/item.py
View file @
53a40166
...
...
@@ -12,6 +12,7 @@ from xmodule.modulestore.inheritance import own_metadata
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InvalidLocationError
from
util.json_request
import
expect_json
,
JsonResponse
from
util.string_utils
import
str_to_bool
from
..transcripts_utils
import
manage_video_subtitles_save
...
...
@@ -74,12 +75,12 @@ def xblock_handler(request, tag=None, course_id=None, branch=None, version_guid=
old_location
=
loc_mapper
()
.
translate_locator_to_location
(
location
)
if
request
.
method
==
'GET'
:
rewrite_static_links
=
request
.
GET
.
get
(
'rewrite_url_links'
,
'True'
)
in
[
'True'
,
'true'
]
rewrite_static_links
=
str_to_bool
(
request
.
GET
.
get
(
'rewrite_url_links'
,
'True'
))
rsp
=
_get_module_info
(
location
,
rewrite_static_links
=
rewrite_static_links
)
return
JsonResponse
(
rsp
)
elif
request
.
method
==
'DELETE'
:
delete_children
=
bool
(
request
.
REQUEST
.
get
(
'recurse'
,
False
))
delete_all_versions
=
bool
(
request
.
REQUEST
.
get
(
'all_versions'
,
False
))
delete_children
=
str_to_
bool
(
request
.
REQUEST
.
get
(
'recurse'
,
False
))
delete_all_versions
=
str_to_
bool
(
request
.
REQUEST
.
get
(
'all_versions'
,
False
))
return
_delete_item_at_location
(
old_location
,
delete_children
,
delete_all_versions
)
else
:
# Since we have a course_id, we are updating an existing xblock.
...
...
common/djangoapps/util/string_utils.py
0 → 100644
View file @
53a40166
"""
Utilities for string manipulation.
"""
import
ast
def
str_to_bool
(
str
):
"""
Converts "true" (case-insensitive) to the boolean True.
Everything else will return False.
"""
try
:
return
ast
.
literal_eval
(
str
.
title
())
except
:
return
False
common/djangoapps/util/tests/test_string_utils.py
0 → 100644
View file @
53a40166
"""
Tests for string_utils.py
"""
from
django.test
import
TestCase
from
util.string_utils
import
str_to_bool
class
StringUtilsTest
(
TestCase
):
"""
Tests for str_to_bool.
"""
def
test_str_to_bool_true
(
self
):
self
.
assertTrue
(
str_to_bool
(
'True'
))
self
.
assertTrue
(
str_to_bool
(
'true'
))
self
.
assertTrue
(
str_to_bool
(
'trUe'
))
def
test_str_to_bool_false
(
self
):
self
.
assertFalse
(
str_to_bool
(
'Tru'
))
self
.
assertFalse
(
str_to_bool
(
'False'
))
self
.
assertFalse
(
str_to_bool
(
'false'
))
self
.
assertFalse
(
str_to_bool
(
''
))
self
.
assertFalse
(
str_to_bool
(
None
))
self
.
assertFalse
(
str_to_bool
(
'anything'
))
self
.
assertFalse
(
str_to_bool
([]))
self
.
assertFalse
(
str_to_bool
({}))
self
.
assertFalse
(
str_to_bool
(
1
))
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