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
714da6ab
Commit
714da6ab
authored
Mar 14, 2014
by
zubiar-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable/disable unicodes in course id's
parent
70233a96
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
3 deletions
+63
-3
cms/djangoapps/contentstore/tests/test_contentstore.py
+26
-1
cms/djangoapps/contentstore/views/course.py
+10
-0
cms/envs/common.py
+3
-0
cms/static/js/index.js
+9
-2
cms/templates/index.html
+1
-0
common/djangoapps/util/string_utils.py
+14
-0
No files found.
cms/djangoapps/contentstore/tests/test_contentstore.py
View file @
714da6ab
# -*- coding: utf-8 -*-
#pylint: disable=E1101
#pylint: disable=E1101
import
json
import
json
...
@@ -1423,6 +1424,15 @@ class ContentStoreTest(ModuleStoreTestCase):
...
@@ -1423,6 +1424,15 @@ class ContentStoreTest(ModuleStoreTestCase):
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
_get_course_id
(
test_course_data
)))
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
_get_course_id
(
test_course_data
)))
return
test_course_data
return
test_course_data
def
assert_create_course_failed
(
self
,
error_message
):
"""
Checks that the course not created.
"""
resp
=
self
.
client
.
ajax_post
(
'/course'
,
self
.
course_data
)
self
.
assertEqual
(
resp
.
status_code
,
400
)
data
=
parse_json
(
resp
)
self
.
assertEqual
(
data
[
'error'
],
error_message
)
def
test_create_course_check_forum_seeding
(
self
):
def
test_create_course_check_forum_seeding
(
self
):
"""Test new course creation and verify forum seeding """
"""Test new course creation and verify forum seeding """
test_course_data
=
self
.
assert_created_course
(
number_suffix
=
uuid4
()
.
hex
)
test_course_data
=
self
.
assert_created_course
(
number_suffix
=
uuid4
()
.
hex
)
...
@@ -1562,6 +1572,21 @@ class ContentStoreTest(ModuleStoreTestCase):
...
@@ -1562,6 +1572,21 @@ class ContentStoreTest(ModuleStoreTestCase):
auth
.
add_users
(
self
.
user
,
CourseCreatorRole
(),
self
.
user
)
auth
.
add_users
(
self
.
user
,
CourseCreatorRole
(),
self
.
user
)
self
.
assert_created_course
()
self
.
assert_created_course
()
def
test_create_course_with_unicode_in_id_disabled
(
self
):
"""
Test new course creation with feature setting: ALLOW_UNICODE_COURSE_ID disabled.
"""
with
mock
.
patch
.
dict
(
'django.conf.settings.FEATURES'
,
{
'ALLOW_UNICODE_COURSE_ID'
:
False
}):
error_message
=
"Special characters not allowed in organization, course number, and course run."
self
.
course_data
[
'org'
]
=
u'Юникода'
self
.
assert_create_course_failed
(
error_message
)
self
.
course_data
[
'number'
]
=
u'échantillon'
self
.
assert_create_course_failed
(
error_message
)
self
.
course_data
[
'run'
]
=
u'όνομα'
self
.
assert_create_course_failed
(
error_message
)
def
assert_course_permission_denied
(
self
):
def
assert_course_permission_denied
(
self
):
"""
"""
Checks that the course did not get created due to a PermissionError.
Checks that the course did not get created due to a PermissionError.
...
@@ -2073,7 +2098,7 @@ def _course_factory_create_course():
...
@@ -2073,7 +2098,7 @@ def _course_factory_create_course():
def
_get_course_id
(
test_course_data
):
def
_get_course_id
(
test_course_data
):
"""Returns the course ID (org/number/run)."""
"""Returns the course ID (org/number/run)."""
return
"{org}/{number}/{run}"
.
format
(
**
test_course_data
)
return
u
"{org}/{number}/{run}"
.
format
(
**
test_course_data
)
def
_test_no_locations
(
test
,
resp
,
status_code
=
200
,
html
=
True
):
def
_test_no_locations
(
test
,
resp
,
status_code
=
200
,
html
=
True
):
...
...
cms/djangoapps/contentstore/views/course.py
View file @
714da6ab
...
@@ -36,6 +36,7 @@ from models.settings.course_details import CourseDetails, CourseSettingsEncoder
...
@@ -36,6 +36,7 @@ from models.settings.course_details import CourseDetails, CourseSettingsEncoder
from
models.settings.course_grading
import
CourseGradingModel
from
models.settings.course_grading
import
CourseGradingModel
from
models.settings.course_metadata
import
CourseMetadata
from
models.settings.course_metadata
import
CourseMetadata
from
util.json_request
import
expect_json
from
util.json_request
import
expect_json
from
util.string_utils
import
_has_non_ascii_characters
from
.access
import
has_course_access
from
.access
import
has_course_access
from
.tabs
import
initialize_course_tabs
from
.tabs
import
initialize_course_tabs
...
@@ -266,6 +267,7 @@ def course_listing(request):
...
@@ -266,6 +267,7 @@ def course_listing(request):
'user'
:
request
.
user
,
'user'
:
request
.
user
,
'request_course_creator_url'
:
reverse
(
'contentstore.views.request_course_creator'
),
'request_course_creator_url'
:
reverse
(
'contentstore.views.request_course_creator'
),
'course_creator_status'
:
_get_course_creator_status
(
request
.
user
),
'course_creator_status'
:
_get_course_creator_status
(
request
.
user
),
'allow_unicode_course_id'
:
settings
.
FEATURES
.
get
(
'ALLOW_UNICODE_COURSE_ID'
,
False
)
})
})
...
@@ -313,6 +315,14 @@ def create_new_course(request):
...
@@ -313,6 +315,14 @@ def create_new_course(request):
display_name
=
request
.
json
.
get
(
'display_name'
)
display_name
=
request
.
json
.
get
(
'display_name'
)
run
=
request
.
json
.
get
(
'run'
)
run
=
request
.
json
.
get
(
'run'
)
# allow/disable unicode characters in course_id according to settings
if
not
settings
.
FEATURES
.
get
(
'ALLOW_UNICODE_COURSE_ID'
):
if
_has_non_ascii_characters
(
org
)
or
_has_non_ascii_characters
(
number
)
or
_has_non_ascii_characters
(
run
):
return
JsonResponse
(
{
'error'
:
_
(
'Special characters not allowed in organization, course number, and course run.'
)},
status
=
400
)
try
:
try
:
dest_location
=
Location
(
u'i4x'
,
org
,
number
,
u'course'
,
run
)
dest_location
=
Location
(
u'i4x'
,
org
,
number
,
u'course'
,
run
)
except
InvalidLocationError
as
error
:
except
InvalidLocationError
as
error
:
...
...
cms/envs/common.py
View file @
714da6ab
...
@@ -86,6 +86,9 @@ FEATURES = {
...
@@ -86,6 +86,9 @@ FEATURES = {
# Turn on/off Microsites feature
# Turn on/off Microsites feature
'USE_MICROSITES'
:
False
,
'USE_MICROSITES'
:
False
,
# Allow creating courses with non-ascii characters in the course id
'ALLOW_UNICODE_COURSE_ID'
:
False
,
}
}
ENABLE_JASMINE
=
False
ENABLE_JASMINE
=
False
...
...
cms/static/js/index.js
View file @
714da6ab
...
@@ -84,8 +84,15 @@ require(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape"],
...
@@ -84,8 +84,15 @@ require(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape"],
if
(
required
)
{
if
(
required
)
{
return
required
;
return
required
;
}
}
if
(
/
\s
/g
.
test
(
item
))
{
if
(
$
(
'.allow-unicode-course-id'
).
val
()
===
'True'
){
return
gettext
(
'Please do not use any spaces in this field.'
);
if
(
/
\s
/g
.
test
(
item
))
{
return
gettext
(
'Please do not use any spaces in this field.'
);
}
}
else
{
if
(
item
!==
encodeURIComponent
(
item
))
{
return
gettext
(
'Please do not use any spaces or special characters in this field.'
);
}
}
}
return
''
;
return
''
;
};
};
...
...
cms/templates/index.html
View file @
714da6ab
...
@@ -123,6 +123,7 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
...
@@ -123,6 +123,7 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
</div>
</div>
<div
class=
"actions"
>
<div
class=
"actions"
>
<input
type=
"hidden"
value=
"${ allow_unicode_course_id }"
class=
"allow-unicode-course-id"
/>
<input
type=
"submit"
value=
"${_('Create')}"
class=
"action action-primary new-course-save"
/>
<input
type=
"submit"
value=
"${_('Create')}"
class=
"action action-primary new-course-save"
/>
<input
type=
"button"
value=
"${_('Cancel')}"
class=
"action action-secondary action-cancel new-course-cancel"
/>
<input
type=
"button"
value=
"${_('Cancel')}"
class=
"action action-secondary action-cancel new-course-cancel"
/>
</div>
</div>
...
...
common/djangoapps/util/string_utils.py
View file @
714da6ab
...
@@ -10,3 +10,17 @@ def str_to_bool(str):
...
@@ -10,3 +10,17 @@ def str_to_bool(str):
An error will be thrown for non-string input (besides None).
An error will be thrown for non-string input (besides None).
"""
"""
return
False
if
str
is
None
else
str
.
lower
()
==
"true"
return
False
if
str
is
None
else
str
.
lower
()
==
"true"
def
_has_non_ascii_characters
(
data_string
):
"""
Check if provided string contains non ascii characters
:param data_string: basestring or unicode object
"""
try
:
data_string
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
return
True
return
False
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