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
91b3a220
Commit
91b3a220
authored
Jan 30, 2013
by
Christina Roberts
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1367 from MITx/fix/cdodge/static-tab-reordering
support reordering of static tabs in studio
parents
8720d1ac
7f32aae4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
3 deletions
+99
-3
cms/djangoapps/contentstore/tests/tests.py
+27
-0
cms/djangoapps/contentstore/views.py
+55
-2
cms/static/coffee/src/views/tabs.coffee
+15
-1
cms/urls.py
+1
-0
common/test/data/full/policies/6.002_Spring_2012.json
+1
-0
No files found.
cms/djangoapps/contentstore/tests/tests.py
View file @
91b3a220
...
...
@@ -350,6 +350,33 @@ class ContentStoreTest(TestCase):
def
test_edit_unit_full
(
self
):
self
.
check_edit_unit
(
'full'
)
def
test_static_tab_reordering
(
self
):
import_from_xml
(
modulestore
(),
'common/test/data/'
,
[
'full'
])
ms
=
modulestore
(
'direct'
)
course
=
ms
.
get_item
(
Location
([
'i4x'
,
'edX'
,
'full'
,
'course'
,
'6.002_Spring_2012'
,
None
]))
# reverse the ordering
reverse_tabs
=
[]
for
tab
in
course
.
tabs
:
if
tab
[
'type'
]
==
'static_tab'
:
reverse_tabs
.
insert
(
0
,
'i4x://edX/full/static_tab/{0}'
.
format
(
tab
[
'url_slug'
]))
resp
=
self
.
client
.
post
(
reverse
(
'reorder_static_tabs'
),
json
.
dumps
({
'tabs'
:
reverse_tabs
}),
"application/json"
)
course
=
ms
.
get_item
(
Location
([
'i4x'
,
'edX'
,
'full'
,
'course'
,
'6.002_Spring_2012'
,
None
]))
# compare to make sure that the tabs information is in the expected order after the server call
course_tabs
=
[]
for
tab
in
course
.
tabs
:
if
tab
[
'type'
]
==
'static_tab'
:
course_tabs
.
append
(
'i4x://edX/full/static_tab/{0}'
.
format
(
tab
[
'url_slug'
]))
self
.
assertEqual
(
reverse_tabs
,
course_tabs
)
def
test_about_overrides
(
self
):
'''
This test case verifies that a course can use specialized override for about data, e.g. /about/Fall_2012/effort.html
...
...
cms/djangoapps/contentstore/views.py
View file @
91b3a220
...
...
@@ -903,6 +903,52 @@ def static_pages(request, org, course, coursename):
def
edit_static
(
request
,
org
,
course
,
coursename
):
return
render_to_response
(
'edit-static-page.html'
,
{})
@login_required
@expect_json
def
reorder_static_tabs
(
request
):
tabs
=
request
.
POST
[
'tabs'
]
course
=
get_course_for_item
(
tabs
[
0
])
if
not
has_access
(
request
.
user
,
course
.
location
):
raise
PermissionDenied
()
# get list of existing static tabs in course
# make sure they are the same lengths (i.e. the number of passed in tabs equals the number
# that we know about) otherwise we can drop some!
existing_static_tabs
=
[
t
for
t
in
course
.
tabs
if
t
[
'type'
]
==
'static_tab'
]
if
len
(
existing_static_tabs
)
!=
len
(
tabs
):
return
HttpResponseBadRequest
()
# load all reference tabs, return BadRequest if we can't find any of them
tab_items
=
[]
for
tab
in
tabs
:
item
=
modulestore
(
'direct'
)
.
get_item
(
Location
(
tab
))
if
item
is
None
:
return
HttpResponseBadRequest
()
tab_items
.
append
(
item
)
# now just go through the existing course_tabs and re-order the static tabs
reordered_tabs
=
[]
static_tab_idx
=
0
for
tab
in
course
.
tabs
:
if
tab
[
'type'
]
==
'static_tab'
:
reordered_tabs
.
append
({
'type'
:
'static_tab'
,
'name'
:
tab_items
[
static_tab_idx
]
.
metadata
.
get
(
'display_name'
),
'url_slug'
:
tab_items
[
static_tab_idx
]
.
location
.
name
})
static_tab_idx
+=
1
else
:
reordered_tabs
.
append
(
tab
)
# OK, re-assemble the static tabs in the new order
course
.
tabs
=
reordered_tabs
modulestore
(
'direct'
)
.
update_metadata
(
course
.
location
,
course
.
metadata
)
return
HttpResponse
()
@login_required
@ensure_csrf_cookie
def
edit_tabs
(
request
,
org
,
course
,
coursename
):
...
...
@@ -914,12 +960,19 @@ def edit_tabs(request, org, course, coursename):
if
not
has_access
(
request
.
user
,
location
):
raise
PermissionDenied
()
static_tabs
=
modulestore
(
'direct'
)
.
get_items
(
static_tabs_loc
)
# see tabs have been uninitialized (e.g. supporing courses created before tab support in studio)
if
course_item
.
tabs
is
None
or
len
(
course_item
.
tabs
)
==
0
:
initialize_course_tabs
(
course_item
)
# first get all static tabs from the tabs list
# we do this because this is also the order in which items are displayed in the LMS
static_tabs_refs
=
[
t
for
t
in
course_item
.
tabs
if
t
[
'type'
]
==
'static_tab'
]
static_tabs
=
[]
for
static_tab_ref
in
static_tabs_refs
:
static_tab_loc
=
Location
(
location
)
.
_replace
(
category
=
'static_tab'
,
name
=
static_tab_ref
[
'url_slug'
])
static_tabs
.
append
(
modulestore
(
'direct'
)
.
get_item
(
static_tab_loc
))
components
=
[
static_tab
.
location
.
url
()
for
static_tab
...
...
cms/static/coffee/src/views/tabs.coffee
View file @
91b3a220
...
...
@@ -15,7 +15,7 @@ class CMS.Views.TabsEdit extends Backbone.View
@
$
(
'.components'
).
sortable
(
handle
:
'.drag-handle'
update
:
(
event
,
ui
)
=>
alert
'not yet implemented!'
update
:
@
tabMoved
helper
:
'clone'
opacity
:
'0.5'
placeholder
:
'component-placeholder'
...
...
@@ -24,6 +24,20 @@ class CMS.Views.TabsEdit extends Backbone.View
items
:
'> .component'
)
tabMoved
:
(
event
,
ui
)
=>
tabs
=
[]
@
$
(
'.component'
).
each
((
idx
,
element
)
=>
tabs
.
push
(
$
(
element
).
data
(
'id'
))
)
$
.
ajax
({
type
:
'POST'
,
url
:
'/reorder_static_tabs'
,
data
:
JSON
.
stringify
({
tabs
:
tabs
}),
contentType
:
'application/json'
})
addNewTab
:
(
event
)
=>
event
.
preventDefault
()
...
...
cms/urls.py
View file @
91b3a220
...
...
@@ -17,6 +17,7 @@ urlpatterns = ('',
url
(
r'^publish_draft$'
,
'contentstore.views.publish_draft'
,
name
=
'publish_draft'
),
url
(
r'^unpublish_unit$'
,
'contentstore.views.unpublish_unit'
,
name
=
'unpublish_unit'
),
url
(
r'^create_new_course'
,
'contentstore.views.create_new_course'
,
name
=
'create_new_course'
),
url
(
r'^reorder_static_tabs'
,
'contentstore.views.reorder_static_tabs'
,
name
=
'reorder_static_tabs'
),
url
(
r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$'
,
'contentstore.views.course_index'
,
name
=
'course_index'
),
...
...
common/test/data/full/policies/6.002_Spring_2012.json
View file @
91b3a220
...
...
@@ -8,6 +8,7 @@
{
"type"
:
"courseware"
},
{
"type"
:
"course_info"
,
"name"
:
"Course Info"
},
{
"type"
:
"static_tab"
,
"url_slug"
:
"syllabus"
,
"name"
:
"Syllabus"
},
{
"type"
:
"static_tab"
,
"url_slug"
:
"resources"
,
"name"
:
"Resources"
},
{
"type"
:
"discussion"
,
"name"
:
"Discussion"
},
{
"type"
:
"wiki"
,
"name"
:
"Wiki"
},
{
"type"
:
"progress"
,
"name"
:
"Progress"
}
...
...
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