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
0bbba8b1
Commit
0bbba8b1
authored
Sep 13, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests and replace ':' with '_' in html_id
* in-progress to fixing support for ':' in url_names
parent
53d0a6ad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
12 deletions
+71
-12
common/djangoapps/xmodule_modifiers.py
+2
-1
common/lib/xmodule/xmodule/modulestore/__init__.py
+30
-4
common/lib/xmodule/xmodule/modulestore/tests/test_location.py
+38
-6
common/lib/xmodule/xmodule/xml_module.py
+1
-1
No files found.
common/djangoapps/xmodule_modifiers.py
View file @
0bbba8b1
...
...
@@ -125,7 +125,7 @@ def add_histogram(get_html, module, user):
mstart
=
getattr
(
module
.
descriptor
,
'start'
)
if
mstart
is
not
None
:
is_released
=
"<font color='red'>Yes!</font>"
if
(
now
>
mstart
)
else
"<font color='green'>Not yet</font>"
staff_context
=
{
'definition'
:
module
.
definition
.
get
(
'data'
),
'metadata'
:
json
.
dumps
(
module
.
metadata
,
indent
=
4
),
'location'
:
module
.
location
,
...
...
@@ -133,6 +133,7 @@ def add_histogram(get_html, module, user):
'source_file'
:
source_file
,
'source_url'
:
'
%
s/
%
s/tree/master/
%
s'
%
(
giturl
,
data_dir
,
source_file
),
'category'
:
str
(
module
.
__class__
.
__name__
),
# Template uses element_id in js function names, so can't allow dashes
'element_id'
:
module
.
location
.
html_id
()
.
replace
(
'-'
,
'_'
),
'edit_link'
:
edit_link
,
'user'
:
user
,
...
...
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
0bbba8b1
...
...
@@ -29,6 +29,9 @@ INVALID_CHARS = re.compile(r"[^\w.-]")
# Names are allowed to have colons.
INVALID_CHARS_NAME
=
re
.
compile
(
r"[^\w.:-]"
)
# html ids can contain word chars and dashes
INVALID_HTML_CHARS
=
re
.
compile
(
r"[^\w-]"
)
_LocationBase
=
namedtuple
(
'LocationBase'
,
'tag org course category name revision'
)
...
...
@@ -45,11 +48,34 @@ class Location(_LocationBase):
__slots__
=
()
@staticmethod
def
_clean
(
value
,
invalid
):
"""
invalid should be a compiled regexp of chars to replace with '_'
"""
return
re
.
sub
(
'_+'
,
'_'
,
invalid
.
sub
(
'_'
,
value
))
@staticmethod
def
clean
(
value
):
"""
Return value, made into a form legal for locations
"""
return
re
.
sub
(
'_+'
,
'_'
,
INVALID_CHARS
.
sub
(
'_'
,
value
))
return
Location
.
_clean
(
value
,
INVALID_CHARS
)
@staticmethod
def
clean_for_url_name
(
value
):
"""
Convert value into a format valid for location names (allows colons).
"""
return
Location
.
_clean
(
value
,
INVALID_CHARS_NAME
)
@staticmethod
def
clean_for_html
(
value
):
"""
Convert a string into a form that's safe for use in html ids, classes, urls, etc.
Replaces all INVALID_HTML_CHARS with '_', collapses multiple '_' chars
"""
return
Location
.
_clean
(
value
,
INVALID_HTML_CHARS
)
@staticmethod
def
is_valid
(
value
):
...
...
@@ -183,9 +209,9 @@ class Location(_LocationBase):
Return a string with a version of the location that is safe for use in
html id attributes
"""
# TODO: is ':' ok in html ids?
return
"-"
.
join
(
str
(
v
)
for
v
in
self
.
list
(
)
if
v
is
not
None
)
.
replace
(
'.'
,
'_'
)
s
=
"-"
.
join
(
str
(
v
)
for
v
in
self
.
list
()
if
v
is
not
None
)
return
Location
.
clean_for_html
(
s
)
def
dict
(
self
):
"""
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_location.py
View file @
0bbba8b1
...
...
@@ -114,12 +114,44 @@ def test_equality():
Location
(
'tag'
,
'org'
,
'course'
,
'category'
,
'name'
)
)
# All the cleaning functions should do the same thing with these
general_pairs
=
[
(
''
,
''
),
(
' '
,
'_'
),
(
'abc,'
,
'abc_'
),
(
'ab fg!@//
\\
aj'
,
'ab_fg_aj'
),
(
u"ab
\xA9
"
,
"ab_"
),
# no unicode allowed for now
]
def
test_clean
():
pairs
=
[
(
''
,
''
),
(
' '
,
'_'
),
(
'abc,'
,
'abc_'
),
(
'ab fg!@//
\\
aj'
,
'ab_fg_aj'
),
(
u"ab
\xA9
"
,
"ab_"
),
# no unicode allowed for now
]
pairs
=
general_pairs
+
[
(
'a:b'
,
'a_b'
),
# no colons in non-name components
(
'a-b'
,
'a-b'
),
# dashes ok
(
'a.b'
,
'a.b'
),
# dot ok
]
for
input
,
output
in
pairs
:
assert_equals
(
Location
.
clean
(
input
),
output
)
def
test_clean_for_url_name
():
pairs
=
general_pairs
+
[
(
'a:b'
,
'a:b'
),
# colons ok in names
(
'a-b'
,
'a-b'
),
# dashes ok in names
(
'a.b'
,
'a.b'
),
# dot ok in names
]
for
input
,
output
in
pairs
:
assert_equals
(
Location
.
clean_for_url_name
(
input
),
output
)
def
test_clean_for_html
():
pairs
=
general_pairs
+
[
(
"a:b"
,
"a_b"
),
# no colons for html use
(
"a-b"
,
"a-b"
),
# dashes ok (though need to be replaced in various use locations. ugh.)
(
'a.b'
,
'a_b'
),
# no dots.
]
for
input
,
output
in
pairs
:
assert_equals
(
Location
.
clean_for_html
(
input
),
output
)
def
test_html_id
():
loc
=
Location
(
"tag://org/course/cat/name:more_name@rev"
)
assert_equals
(
loc
.
html_id
(),
"tag-org-course-cat-name_more_name-rev"
)
common/lib/xmodule/xmodule/xml_module.py
View file @
0bbba8b1
...
...
@@ -28,7 +28,7 @@ def is_pointer_tag(xml_obj):
No children, one attribute named url_name.
Special case for course roots: the pointer is
<course url_name="something" org="myorg"
course="course">
<course url_name="something" org="myorg" course="course">
xml_obj: an etree Element
...
...
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