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
c70f29e8
Commit
c70f29e8
authored
Oct 12, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wire up import to the frontend, and make sure that it puts it into the already extant course
parent
3d2a1c24
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
14 deletions
+53
-14
cms/djangoapps/contentstore/views.py
+22
-13
cms/templates/import.html
+31
-1
No files found.
cms/djangoapps/contentstore/views.py
View file @
c70f29e8
...
...
@@ -13,6 +13,8 @@ import shutil
from
collections
import
defaultdict
from
uuid
import
uuid4
from
lxml
import
etree
from
path
import
path
from
shutil
import
rmtree
# to install PIL on MacOSX: 'easy_install http://dist.repoze.org/PIL-1.1.6.tar.gz'
from
PIL
import
Image
...
...
@@ -849,7 +851,8 @@ def asset_index(request, org, course, name):
def
edge
(
request
):
return
render_to_response
(
'university_profiles/edge.html'
,
{})
@ensure_csrf_cookie
@login_required
def
import_course
(
request
,
org
,
course
,
name
):
location
=
[
'i4x'
,
org
,
course
,
'course'
,
name
]
...
...
@@ -859,42 +862,48 @@ def import_course(request, org, course, name):
raise
PermissionDenied
()
if
request
.
method
==
'POST'
:
filename
=
request
.
FILES
[
'
file
'
]
.
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.'
}))
temp_filepath
=
settings
.
GITHUB_REPO_ROOT
+
'/'
+
filename
data_root
=
path
(
settings
.
GITHUB_REPO_ROOT
)
temp_filepath
=
data_root
/
filename
logging
.
debug
(
'importing course to {0}'
.
format
(
temp_filepath
))
# stream out the uploaded files in chunks to disk
temp_file
=
open
(
temp_filepath
,
'wb+'
)
for
chunk
in
request
.
FILES
[
'
file
'
]
.
chunks
():
for
chunk
in
request
.
FILES
[
'
course-data
'
]
.
chunks
():
temp_file
.
write
(
chunk
)
temp_file
.
close
()
# @todo: don't assume the top-level directory that was unziped was the same name (but without .tar.gz)
course_dir
=
filename
.
replace
(
'.tar.gz'
,
''
)
tf
=
tarfile
.
open
(
temp_filepath
)
tf
.
extractall
(
settings
.
GITHUB_REPO_ROOT
+
'/'
)
shutil
.
rmtree
(
data_root
/
course_dir
)
tf
.
extractall
(
data_root
+
'/'
)
os
.
remove
(
temp_filepath
)
# remove the .tar.gz file
# @todo: don't assume the top-level directory that was unziped was the same name (but without .tar.gz)
course_dir
=
filename
.
replace
(
'.tar.gz'
,
''
)
with
open
(
data_root
/
course_dir
/
'course.xml'
,
'r'
)
as
course_file
:
course_data
=
etree
.
parse
(
course_file
,
parser
=
edx_xml_parser
)
course_data_root
=
course_data
.
getroot
()
course_data_root
.
set
(
'org'
,
org
)
course_data_root
.
set
(
'course'
,
course
)
course_data_root
.
set
(
'url_name'
,
name
)
with
open
(
temp_filepath
/
course_dir
/
'course.xml'
,
'rw'
)
as
course_file
:
course_data
=
etree
.
parse
(
course_file
,
parser
=
edx_xml_parser
)
.
getroot
()
course_data
.
set
(
'org'
,
org
)
course_data
.
set
(
'course'
,
course
)
course_data
.
set
(
'url_name'
,
name
)
with
open
(
data_root
/
course_dir
/
'course.xml'
,
'w'
)
as
course_file
:
course_data
.
write
(
course_file
)
module_store
,
course_items
=
import_from_xml
(
modulestore
(
'direct'
),
settings
.
GITHUB_REPO_ROOT
,
[
course_dir
],
load_error_modules
=
False
,
static_content_store
=
contentstore
())
# remove content directory - we *shouldn't* need this any longer :-)
shutil
.
rmtree
(
temp_filepath
.
replace
(
'.tar.gz'
,
''
)
)
shutil
.
rmtree
(
data_root
/
course_dir
)
logging
.
debug
(
'new course at {0}'
.
format
(
course_items
[
0
]
.
location
))
...
...
cms/templates/import.html
View file @
c70f29e8
...
...
@@ -15,7 +15,7 @@
<p>
Please note that if your course has any problems with auto-generated
<code>
url_name
</code>
nodes,
re-importing your course could cause the loss of student data associated with those problems.
</p>
</div>
<form
class=
"import-form"
>
<form
action=
"${reverse('import_course', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name=context_course.location.name))}"
method=
"post"
enctype=
"multipart/form-data"
class=
"import-form"
>
<h2>
Course to import:
</h2>
<a
href=
"#"
class=
"choose-file-button"
>
Choose File
</a>
<p
class=
"file-name-block"
><span
class=
"file-name"
></span><a
href=
"#"
class=
"choose-file-button-inline"
>
change
</a></p>
...
...
@@ -25,4 +25,33 @@
</article>
</div>
</div>
</
%
block>
<
%
block
name=
"jsextra"
>
<script
src=
"http://malsup.github.com/jquery.form.js"
></script>
<script>
(
function
()
{
var
bar
=
$
(
'.bar'
);
var
percent
=
$
(
'.percent'
);
var
status
=
$
(
'#status'
);
$
(
'form'
).
ajaxForm
({
beforeSend
:
function
()
{
status
.
empty
();
var
percentVal
=
'0%'
;
bar
.
width
(
percentVal
)
percent
.
html
(
percentVal
);
},
uploadProgress
:
function
(
event
,
position
,
total
,
percentComplete
)
{
var
percentVal
=
percentComplete
+
'%'
;
bar
.
width
(
percentVal
)
percent
.
html
(
percentVal
);
},
complete
:
function
(
xhr
)
{
status
.
html
(
xhr
.
responseText
);
}
});
})();
</script>
</
%
block>
\ No newline at end of file
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