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
cba888c6
Commit
cba888c6
authored
Dec 28, 2012
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1212 from MITx/fix/cdodge/handout-links
Fix/cdodge/handout links
parents
bd8661a8
6d20292a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
5 deletions
+36
-5
cms/djangoapps/contentstore/module_info_model.py
+7
-3
cms/djangoapps/contentstore/tests/tests.py
+24
-0
cms/djangoapps/contentstore/views.py
+5
-2
No files found.
cms/djangoapps/contentstore/module_info_model.py
View file @
cba888c6
import
logging
from
static_replace
import
replace_urls
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
...
...
@@ -7,7 +7,7 @@ from lxml import etree
import
re
from
django.http
import
HttpResponseBadRequest
,
Http404
def
get_module_info
(
store
,
location
,
parent_location
=
None
):
def
get_module_info
(
store
,
location
,
parent_location
=
None
,
rewrite_static_links
=
False
):
try
:
if
location
.
revision
is
None
:
module
=
store
.
get_item
(
location
)
...
...
@@ -16,9 +16,13 @@ def get_module_info(store, location, parent_location = None):
except
ItemNotFoundError
:
raise
Http404
data
=
module
.
definition
[
'data'
]
if
rewrite_static_links
:
data
=
replace_urls
(
module
.
definition
[
'data'
],
course_namespace
=
Location
([
module
.
location
.
tag
,
module
.
location
.
org
,
module
.
location
.
course
,
None
,
None
]))
return
{
'id'
:
module
.
location
.
url
(),
'data'
:
module
.
definition
[
'data'
]
,
'data'
:
data
,
'metadata'
:
module
.
metadata
}
...
...
cms/djangoapps/contentstore/tests/tests.py
View file @
cba888c6
...
...
@@ -7,6 +7,7 @@ from django.conf import settings
from
django.core.urlresolvers
import
reverse
from
path
import
path
from
tempfile
import
mkdtemp
import
json
from
student.models
import
Registration
from
django.contrib.auth.models
import
User
...
...
@@ -417,6 +418,29 @@ class ContentStoreTest(TestCase):
shutil
.
rmtree
(
root_dir
)
def
test_course_handouts_rewrites
(
self
):
ms
=
modulestore
(
'direct'
)
cs
=
contentstore
()
import_from_xml
(
ms
,
'common/test/data/'
,
[
'full'
])
handout_location
=
Location
([
'i4x'
,
'edX'
,
'full'
,
'course_info'
,
'handouts'
])
resp
=
self
.
client
.
get
(
reverse
(
'module_info'
,
kwargs
=
{
'module_location'
:
handout_location
}))
self
.
assertEqual
(
resp
.
status_code
,
200
)
# check that /static/ has been converted to the full path
self
.
assertContains
(
resp
,
'/c4x/edX/full/asset/handouts_schematic_tutorial.pdf'
)
cms/djangoapps/contentstore/views.py
View file @
cba888c6
...
...
@@ -1009,14 +1009,17 @@ def module_info(request, module_location):
if
request
.
method
==
'POST'
and
'HTTP_X_HTTP_METHOD_OVERRIDE'
in
request
.
META
:
real_method
=
request
.
META
[
'HTTP_X_HTTP_METHOD_OVERRIDE'
]
else
:
real_method
=
request
.
method
real_method
=
request
.
method
rewrite_static_links
=
request
.
GET
.
get
(
'rewrite_url_links'
,
'True'
)
in
[
'True'
,
'true'
]
logging
.
debug
(
'rewrite_static_links = {0} {1}'
.
format
(
request
.
GET
.
get
(
'rewrite_url_links'
,
'False'
),
rewrite_static_links
))
# check that logged in user has permissions to this item
if
not
has_access
(
request
.
user
,
location
):
raise
PermissionDenied
()
if
real_method
==
'GET'
:
return
HttpResponse
(
json
.
dumps
(
get_module_info
(
get_modulestore
(
location
),
location
)),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
get_module_info
(
get_modulestore
(
location
),
location
,
rewrite_static_links
=
rewrite_static_links
)),
mimetype
=
"application/json"
)
elif
real_method
==
'POST'
or
real_method
==
'PUT'
:
return
HttpResponse
(
json
.
dumps
(
set_module_info
(
get_modulestore
(
location
),
location
,
request
.
POST
)),
mimetype
=
"application/json"
)
else
:
...
...
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