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
02a325b0
Commit
02a325b0
authored
Oct 11, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First stab at an import page. Needs styling
parent
ac71da15
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
35 deletions
+64
-35
cms/djangoapps/contentstore/views.py
+48
-27
cms/static/sass/_header.scss
+9
-0
cms/templates/course_index.html
+0
-2
cms/templates/index.html
+0
-2
cms/templates/overview.html
+0
-1
cms/templates/widgets/header.html
+1
-1
cms/urls.py
+6
-2
No files found.
cms/djangoapps/contentstore/views.py
View file @
02a325b0
...
...
@@ -12,6 +12,7 @@ import tarfile
import
shutil
from
collections
import
defaultdict
from
uuid
import
uuid4
from
lxml
import
etree
# to install PIL on MacOSX: 'easy_install http://dist.repoze.org/PIL-1.1.6.tar.gz'
from
PIL
import
Image
...
...
@@ -24,6 +25,7 @@ from django_future.csrf import ensure_csrf_cookie
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
django
import
forms
from
django.shortcuts
import
redirect
from
xmodule.modulestore
import
Location
from
xmodule.x_module
import
ModuleSystem
...
...
@@ -51,6 +53,7 @@ from .utils import get_course_location_for_item, get_lms_link_for_item, compute_
from
xmodule.templates
import
all_templates
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.xml
import
edx_xml_parser
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -259,7 +262,8 @@ def edit_unit(request, location):
published_date
=
None
return
render_to_response
(
'unit.html'
,
{
'context_course'
:
course
,
'context_course'
:
item
,
'active_tab'
:
'courseware'
,
'unit'
:
item
,
'unit_location'
:
location
,
'components'
:
components
,
...
...
@@ -845,45 +849,62 @@ def asset_index(request, org, course, name):
def
edge
(
request
):
return
render_to_response
(
'university_profiles/edge.html'
,
{})
def
import_course
(
request
):
if
request
.
method
!=
'POST'
:
# (cdodge) @todo: Is there a way to do a - say - 'raise Http400'?
return
HttpResponseBadRequest
()
filename
=
request
.
FILES
[
'file'
]
.
name
def
import_course
(
request
,
org
,
course
,
name
):
location
=
[
'i4x'
,
org
,
course
,
'course'
,
name
]
if
not
filename
.
endswith
(
'.tar.gz'
):
return
HttpResponse
(
json
.
dumps
({
'ErrMsg'
:
'We only support uploading a .tar.gz file.'
}))
# check that logged in user has permissions to this item
if
not
has_access
(
request
.
user
,
location
):
raise
PermissionDenied
()
temp_filepath
=
settings
.
GITHUB_REPO_ROOT
+
'/'
+
filename
if
request
.
method
==
'POST'
:
filename
=
request
.
FILES
[
'file'
]
.
name
logging
.
debug
(
'importing course to {0}'
.
format
(
temp_filepath
))
if
not
filename
.
endswith
(
'.tar.gz'
):
return
HttpResponse
(
json
.
dumps
({
'ErrMsg'
:
'We only support uploading a .tar.gz file.'
}))
# stream out the uploaded files in chunks to disk
temp_file
=
open
(
temp_filepath
,
'wb+'
)
for
chunk
in
request
.
FILES
[
'file'
]
.
chunks
():
temp_file
.
write
(
chunk
)
temp_file
.
close
()
temp_filepath
=
settings
.
GITHUB_REPO_ROOT
+
'/'
+
filename
tf
=
tarfile
.
open
(
temp_filepath
)
tf
.
extractall
(
settings
.
GITHUB_REPO_ROOT
+
'/'
)
logging
.
debug
(
'importing course to {0}'
.
format
(
temp_filepath
))
os
.
remove
(
temp_filepath
)
# remove the .tar.gz file
# stream out the uploaded files in chunks to disk
temp_file
=
open
(
temp_filepath
,
'wb+'
)
for
chunk
in
request
.
FILES
[
'file'
]
.
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)
tf
=
tarfile
.
open
(
temp_filepath
)
tf
.
extractall
(
settings
.
GITHUB_REPO_ROOT
+
'/'
)
course_dir
=
filename
.
replace
(
'.tar.gz'
,
''
)
os
.
remove
(
temp_filepath
)
# remove the .tar.gz file
module_store
,
course_items
=
import_from_xml
(
modulestore
(
'direct'
),
settings
.
GITHUB_REPO_ROOT
,
[
course_dir
],
load_error_modules
=
False
,
static_content_store
=
contentstore
())
# @todo: don't assume the top-level directory that was unziped was the same name (but without .tar.gz)
# remove content directory - we *shouldn't* need this any longer :-)
shutil
.
rmtree
(
temp_filepath
.
replace
(
'.tar.gz'
,
''
))
course_dir
=
filename
.
replace
(
'.tar.gz'
,
''
)
logging
.
debug
(
'new course at {0}'
.
format
(
course_items
[
0
]
.
location
))
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
)
course_data
.
write
(
course_file
)
create_all_course_groups
(
request
.
user
,
course_items
[
0
]
.
location
)
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'
,
''
))
logging
.
debug
(
'new course at {0}'
.
format
(
course_items
[
0
]
.
location
))
create_all_course_groups
(
request
.
user
,
course_items
[
0
]
.
location
)
return
HttpResponse
(
json
.
dumps
({
'Status'
:
'OK'
}))
else
:
course_module
=
modulestore
()
.
get_item
(
location
)
return
HttpResponse
(
json
.
dumps
({
'Status'
:
'OK'
}))
return
render_to_response
(
'import.html'
,
{
'context_course'
:
course_module
,
'active_tab'
:
'import'
,
})
cms/static/sass/_header.scss
View file @
02a325b0
...
...
@@ -38,6 +38,15 @@ body.no-header {
@include
active
;
}
#import-tab
{
@include
box-shadow
(
1px
0
0
#787981
inset
,
-1px
0
0
#3d3e44
inset
,
1px
0
0
#787981
,
-1px
0
0
#3d3e44
);
background
:
rgba
(
255
,
0
,
0
,
.5
);
&
:hover
{
background
:
rgba
(
255
,
0
,
0
,
.7
);
}
}
.left
{
width
:
700px
;
}
...
...
cms/templates/course_index.html
View file @
02a325b0
...
...
@@ -10,7 +10,5 @@
<section
class=
"main-content"
>
</section>
<
%
include
file=
"widgets/upload_assets.html"
/>
</section>
</
%
block>
cms/templates/index.html
View file @
02a325b0
...
...
@@ -28,6 +28,4 @@
</section>
<
%
include
file=
"widgets/import-course.html"
/>
</
%
block>
cms/templates/overview.html
View file @
02a325b0
...
...
@@ -92,7 +92,6 @@
% endfor
</article>
</div>
<
%
include
file=
"widgets/upload_assets.html"
/>
</div>
<footer></footer>
</
%
block>
cms/templates/widgets/header.html
View file @
02a325b0
...
...
@@ -13,7 +13,7 @@
<li><a
href=
"${reverse('static_pages', kwargs=dict(org=ctx_loc.org, course=ctx_loc.course, coursename=ctx_loc.name))}"
id=
'pages-tab'
>
Pages
</a></li>
<li><a
href=
"${reverse('asset_index', kwargs=dict(org=ctx_loc.org, course=ctx_loc.course, name=ctx_loc.name))}"
id=
'assets-tab'
>
Assets
</a></li>
<li><a
href=
"${reverse('manage_users', kwargs=dict(location=ctx_loc))}"
id=
'users-tab'
>
Users
</a></li>
<li><a
href=
"${reverse('
course_index
', kwargs=dict(org=ctx_loc.org, course=ctx_loc.course, name=ctx_loc.name))}"
id=
'import-tab'
class=
"wip-box"
>
Import
</a></li>
<li><a
href=
"${reverse('
import_course
', kwargs=dict(org=ctx_loc.org, course=ctx_loc.course, name=ctx_loc.name))}"
id=
'import-tab'
class=
"wip-box"
>
Import
</a></li>
</ul>
% endif
</div>
...
...
cms/urls.py
View file @
02a325b0
...
...
@@ -16,8 +16,14 @@ urlpatterns = ('',
url
(
r'^create_draft$'
,
'contentstore.views.create_draft'
,
name
=
'create_draft'
),
url
(
r'^publish_draft$'
,
'contentstore.views.publish_draft'
,
name
=
'publish_draft'
),
url
(
r'^unpublish_unit$'
,
'contentstore.views.unpublish_unit'
,
name
=
'unpublish_unit'
),
url
(
r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$'
,
'contentstore.views.course_index'
,
name
=
'course_index'
),
url
(
r'^(?P<org>[^/]+)/(?P<course>[^/]+)/import/(?P<name>[^/]+)$'
,
'contentstore.views.import_course'
,
name
=
'import_course'
),
url
(
r'^github_service_hook$'
,
'github_sync.views.github_post_receive'
),
url
(
r'^preview/modx/(?P<preview_id>[^/]*)/(?P<location>.*?)/(?P<dispatch>[^/]*)$'
,
'contentstore.views.preview_dispatch'
,
name
=
'preview_dispatch'
),
...
...
@@ -46,8 +52,6 @@ urlpatterns = ('',
url
(
r'^edge$'
,
'contentstore.views.edge'
,
name
=
'edge'
),
url
(
r'^heartbeat$'
,
include
(
'heartbeat.urls'
)),
url
(
r'import_course$'
,
'contentstore.views.import_course'
,
name
=
'import_course'
),
)
# User creation and updating views
...
...
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