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
e607bc70
Commit
e607bc70
authored
Jun 11, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull assets into Mako template for PDF textbooks
parent
19d65f81
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
5 deletions
+54
-5
cms/djangoapps/contentstore/views/assets.py
+32
-0
cms/djangoapps/contentstore/views/course.py
+18
-4
cms/templates/textbooks.html
+4
-1
No files found.
cms/djangoapps/contentstore/views/assets.py
View file @
e607bc70
...
...
@@ -35,6 +35,35 @@ from .access import get_location_and_verify_access
__all__
=
[
'asset_index'
,
'upload_asset'
,
'import_course'
,
'generate_export_course'
,
'export_course'
]
def
assets_to_json_dict
(
assets
):
ret
=
[]
for
asset
in
assets
:
obj
=
{
"name"
:
asset
.
get
(
"displayname"
,
""
),
"chunkSize"
:
asset
.
get
(
"chunkSize"
,
0
),
"path"
:
asset
.
get
(
"filename"
,
""
),
"length"
:
asset
.
get
(
"length"
,
0
),
}
uploaded
=
asset
.
get
(
"uploadDate"
)
if
uploaded
:
obj
[
"uploaded"
]
=
uploaded
.
isoformat
()
thumbnail
=
asset
.
get
(
"thumbnail_location"
)
if
thumbnail
:
obj
[
"thumbnail"
]
=
thumbnail
idInfo
=
asset
.
get
(
"_id"
)
if
idInfo
:
obj
[
"id"
]
=
"/{tag}/{org}/{course}/{revision}/{category}/{name}"
.
format
(
org
=
idInfo
.
get
(
"org"
,
""
),
course
=
idInfo
.
get
(
"course"
,
""
),
revision
=
idInfo
.
get
(
"revision"
,
""
),
tag
=
idInfo
.
get
(
"tag"
,
""
),
category
=
idInfo
.
get
(
"category"
,
""
),
name
=
idInfo
.
get
(
"name"
,
""
),
)
ret
.
append
(
obj
)
return
ret
@login_required
@ensure_csrf_cookie
def
asset_index
(
request
,
org
,
course
,
name
):
...
...
@@ -59,6 +88,9 @@ def asset_index(request, org, course, name):
# sort in reverse upload date order
assets
=
sorted
(
assets
,
key
=
lambda
asset
:
asset
[
'uploadDate'
],
reverse
=
True
)
if
request
.
META
.
get
(
'HTTP_ACCEPT'
,
""
)
.
startswith
(
"application/json"
):
return
HttpResponse
(
json
.
dumps
(
assets_to_json_dict
(
assets
)),
content_type
=
"application/json"
)
asset_display
=
[]
for
asset
in
assets
:
asset_id
=
asset
[
'_id'
]
...
...
cms/djangoapps/contentstore/views/course.py
View file @
e607bc70
...
...
@@ -16,6 +16,9 @@ from xmodule.modulestore.exceptions import (
ItemNotFoundError
,
InvalidLocationError
)
from
xmodule.modulestore
import
Location
from
xmodule.contentstore.django
import
contentstore
from
xmodule.contentstore.content
import
StaticContent
from
contentstore.course_info_model
import
(
get_course_updates
,
update_course_updates
,
delete_course_update
)
from
contentstore.utils
import
(
...
...
@@ -29,6 +32,7 @@ from auth.authz import create_all_course_groups, is_user_in_creator_group
from
util.json_request
import
expect_json
from
.access
import
has_access
,
get_location_and_verify_access
from
.assets
import
assets_to_json_dict
from
.requests
import
get_request_method
from
.tabs
import
initialize_course_tabs
from
.component
import
(
...
...
@@ -424,13 +428,23 @@ def textbook_index(request, org, course, name):
upload_asset_callback_url
=
reverse
(
'upload_asset'
,
kwargs
=
{
'org'
:
org
,
'course'
:
course
,
'coursename'
:
name
'coursename'
:
name
,
})
asset_index_url
=
reverse
(
'asset_index'
,
kwargs
=
{
'org'
:
org
,
'course'
:
course
,
'name'
:
name
,
})
course_reference
=
StaticContent
.
compute_location
(
org
,
course
,
name
)
assets_db_objs
=
contentstore
()
.
get_all_content_for_course
(
course_reference
)
assets_json_objs
=
assets_to_json_dict
(
assets_db_objs
)
location
=
get_location_and_verify_access
(
request
,
org
,
course
,
name
)
course
=
modulestore
()
.
get_item
(
location
,
depth
=
3
)
course
_obj
=
modulestore
()
.
get_item
(
location
,
depth
=
3
)
return
render_to_response
(
'textbooks.html'
,
{
'context_course'
:
course
,
'course'
:
course
,
'context_course'
:
course_obj
,
'course'
:
course_obj
,
'assets'
:
assets_json_objs
,
'upload_asset_callback_url'
:
upload_asset_callback_url
,
'asset_index_url'
:
asset_index_url
,
})
cms/templates/textbooks.html
View file @
e607bc70
<
%
inherit
file=
"base.html"
/>
<
%
namespace
name=
'static'
file=
'static_content.html'
/>
<
%!
import
json
%
>
<
%
block
name=
"title"
>
Textbooks
</
%
block>
<
%
block
name=
"bodyclass"
>
is-signedin course textbooks
</
%
block>
...
...
@@ -25,6 +26,7 @@
<
%
block
name=
"jsextra"
>
<script
type=
"text/javascript"
>
window
.
UPLOAD_ASSET_CALLBACK_URL
=
"${upload_asset_callback_url}"
window
.
ASSET_INDEX_URL
=
"${asset_index_url}"
CMS
.
Models
.
Textbook
=
Backbone
.
Model
.
extend
({
defaults
:
{
...
...
@@ -146,6 +148,7 @@ CMS.Views.TextbookEdit = Backbone.View.extend({
})
CMS
.
Collections
.
TextbookSet
=
Backbone
.
Collection
.
extend
({
model
:
CMS
.
Models
.
Textbook
,
url
:
ASSET_INDEX_URL
,
initialize
:
function
()
{
this
.
listenTo
(
this
,
"editOne"
,
this
.
editOne
);
},
...
...
@@ -358,7 +361,7 @@ var section = new CMS.Models.Section({
id
:
"${course.id}"
,
name
:
"${course.display_name_with_default | h}"
});
var
textbooks
=
new
CMS
.
Collections
.
TextbookSet
();
var
textbooks
=
new
CMS
.
Collections
.
TextbookSet
(
$
{
json
.
dumps
(
assets
)}
);
var
tbView
=
new
CMS
.
Views
.
ListTextbooks
({
collection
:
textbooks
});
$
(
function
()
{
...
...
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