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
513b6cab
Commit
513b6cab
authored
Aug 14, 2013
by
Julian Arni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small review fixes.
Comments, httpresponse -> jsonresponse; make sure errors get relayed.
parent
798d07a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
27 deletions
+36
-27
cms/djangoapps/contentstore/views/assets.py
+28
-23
cms/templates/import.html
+8
-4
No files found.
cms/djangoapps/contentstore/views/assets.py
View file @
513b6cab
...
...
@@ -39,8 +39,9 @@ from util.json_request import JsonResponse
__all__
=
[
'asset_index'
,
'upload_asset'
,
'import_course'
,
'generate_export_course'
,
'export_course'
]
MAX_UP_LENGTH
=
20000352
MAX_UP_LENGTH
=
20000352
# Max chunk size
# Regex to capture Content-Range header ranges.
CONTENT_RE
=
re
.
compile
(
r"(?P<start>\d{1,11})-(?P<stop>\d{1,11})/(?P<end>\d{1,11})"
)
def
assets_to_json_dict
(
assets
):
...
...
@@ -282,9 +283,10 @@ def import_course(request, org, course, name):
filename
=
request
.
FILES
[
'course-data'
]
.
name
if
not
filename
.
endswith
(
'.tar.gz'
):
return
HttpResponse
(
json
.
dumps
({
'ErrMsg'
:
'We only support uploading a .tar.gz file.'
}))
return
JsonResponse
(
{
'ErrMsg'
:
'We only support uploading a .tar.gz file.'
},
status
=
415
)
temp_filepath
=
course_dir
/
filename
if
not
course_dir
.
isdir
():
...
...
@@ -293,18 +295,21 @@ def import_course(request, org, course, name):
logging
.
debug
(
'importing course to {0}'
.
format
(
temp_filepath
))
# Get upload chunks byte ranges
matches
=
CONTENT_RE
.
search
(
request
.
META
[
"HTTP_CONTENT_RANGE"
])
content_range
=
matches
.
groupdict
()
try
:
matches
=
CONTENT_RE
.
search
(
request
.
META
[
"HTTP_CONTENT_RANGE"
])
content_range
=
matches
.
groupdict
()
except
KeyError
:
content_range
=
{
'start'
:
0
,
'stop'
:
9
,
'end'
:
10
}
# stream out the uploaded files in chunks to disk
if
int
(
content_range
[
'start'
])
==
0
:
temp_file
=
open
(
temp_filepath
,
'wb+'
)
mode
=
"wb+"
else
:
temp_file
=
open
(
temp_filepath
,
'ab+'
)
mode
=
"ab+"
for
chunk
in
request
.
FILES
[
'course-data'
]
.
chunks
()
:
temp_file
.
write
(
chunk
)
temp_file
.
close
(
)
with
open
(
temp_filepath
,
mode
)
as
temp_file
:
for
chunk
in
request
.
FILES
[
'course-data'
]
.
chunks
():
temp_file
.
write
(
chunk
)
size
=
os
.
path
.
getsize
(
temp_filepath
)
...
...
@@ -341,17 +346,17 @@ def import_course(request, org, course, name):
# find the 'course.xml' file
dirpath
=
None
for
dirpath
,
_dirnames
,
filenames
in
os
.
walk
(
course_dir
):
for
fname
in
filenames
:
if
fname
==
'course.xml'
:
break
if
fname
==
'course.xml'
:
break
if
fname
!=
'course.xml'
:
return
HttpResponse
(
json
.
dumps
({
'ErrMsg'
:
'Could not find the course.xml file in the package.'
})
)
coursexmls
=
((
d
,
f
)
for
d
,
_
,
f
in
os
.
walk
(
course_dir
)
if
f
.
count
(
'course.xml'
)
>
0
)
try
:
(
dirpath
,
fname
)
=
coursexmls
.
next
()
except
StopIteration
:
return
JsonResponse
(
{
'ErrMsg'
:
'Could not find the course.xml file in the package.'
},
status
=
415
)
logging
.
debug
(
'found course.xml at {0}'
.
format
(
dirpath
))
...
...
@@ -382,7 +387,7 @@ def import_course(request, org, course, name):
os
.
remove
(
lock_filepath
)
return
HttpResponse
(
json
.
dumps
({
'Status'
:
'OK'
})
)
return
JsonResponse
({
'Status'
:
'OK'
}
)
else
:
course_module
=
modulestore
()
.
get_item
(
location
)
...
...
cms/templates/import.html
View file @
513b6cab
...
...
@@ -71,7 +71,14 @@ $('#fileupload').fileupload({
add
:
function
(
e
,
data
)
{
submitBtn
.
show
().
click
(
function
(
e
){
e
.
preventDefault
();
data
.
submit
();
data
.
submit
().
complete
(
function
(
result
,
textStatus
,
xhr
)
{
if
(
result
.
status
!=
200
)
{
alert
(
'${_("Your import has failed.")}
\
n
\
n'
+
JSON
.
parse
(
result
.
responseText
)[
"ErrMsg"
]);
submitBtn
.
show
();
bar
.
hide
();
}
});
});
},
...
...
@@ -86,9 +93,6 @@ $('#fileupload').fileupload({
alert
(
'${_("Your import was successful.")}'
);
window
.
location
=
'${successful_import_redirect_url}'
;
},
fail
:
function
(
e
,
data
)
{
alert
(
'${_("Your import has failed.")}
\
n
\
n'
);
},
});
...
...
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