-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a /jump_to_id/ shortcut for producing more durable links between cou... #452
Changes from all commits
1c79b9c
63c5cfd
059450c
80e0b99
e24eb3e
565564a
345d2af
f78e3a2
c5ef8dc
6f3b49a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,35 @@ def try_staticfiles_lookup(path): | |
return url | ||
|
||
|
||
def replace_jump_to_id_urls(text, course_id, jump_to_id_base_url): | ||
""" | ||
This will replace a link to another piece of courseware to a 'jump_to' | ||
URL that will redirect to the right place in the courseware | ||
NOTE: This is similar to replace_course_urls in terms of functionality | ||
but it is intended to be used when we only have a 'id' that the | ||
course author provides. This is much more helpful when using | ||
Studio authored courses since they don't need to know the path. This | ||
is also durable with respect to item moves. | ||
text: The content over which to perform the subtitutions | ||
course_id: The course_id in which this rewrite happens | ||
jump_to_id_base_url: | ||
A app-tier (e.g. LMS) absolute path to the base of the handler that will perform the | ||
redirect. e.g. /courses/<org>/<course>/<run>/jump_to_id. NOTE the <id> will be appended to | ||
the end of this URL at re-write time | ||
output: <text> after the link rewriting rules are applied | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please give an example of a |
||
|
||
def replace_jump_to_id_url(match): | ||
quote = match.group('quote') | ||
rest = match.group('rest') | ||
return "".join([quote, jump_to_id_base_url + rest, quote]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this been tested with non-ASCII text? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, any suggestions on how to do so with the XML 'toy' course? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just add some non-ASCII chars inside and outside the link text in toyjumpto.html? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK added some chinese text to toyjumpto.html. |
||
|
||
return re.sub(_url_replace_regex('/jump_to_id/'), replace_jump_to_id_url, text) | ||
|
||
|
||
def replace_course_urls(text, course_id): | ||
""" | ||
Replace /course/$stuff urls with /courses/$course_id/$stuff urls | ||
|
@@ -53,7 +82,6 @@ def replace_course_urls(text, course_id): | |
returns: text with the links replaced | ||
""" | ||
|
||
|
||
def replace_course_url(match): | ||
quote = match.group('quote') | ||
rest = match.group('rest') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a href="/jump_to_id/vertical_test">This is a link to another page and some Chinese 四節比分和七年前</a> <p>Some more Chinese 四節比分和七年前</p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html filename="toyjumpto.html"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for escaping? What kinds of things can be in a name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location.name here is always a GUID when it is created in Studio. If it's imported from an XML course, then it will be the 'url_name', which - I presume - is appropriate for URL purposes.