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
de4abe30
Commit
de4abe30
authored
Aug 20, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #464 from MITx/kimth/textbook
Kimth/textbook
parents
259e2136
9852a581
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
8 deletions
+36
-8
common/lib/xmodule/xmodule/course_module.py
+32
-5
lms/djangoapps/staticbook/views.py
+2
-1
lms/templates/staticbook.html
+2
-2
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
de4abe30
from
fs.errors
import
ResourceNotFoundError
import
time
import
logging
import
requests
from
lxml
import
etree
from
xmodule.util.decorators
import
lazyproperty
...
...
@@ -15,18 +16,44 @@ class CourseDescriptor(SequenceDescriptor):
module_class
=
SequenceModule
class
Textbook
:
def
__init__
(
self
,
title
,
table_of_contents
_url
):
def
__init__
(
self
,
title
,
book
_url
):
self
.
title
=
title
self
.
table_of_contents_url
=
table_of_contents_url
self
.
book_url
=
book_url
self
.
table_of_contents
=
self
.
_get_toc_from_s3
()
@classmethod
def
from_xml_object
(
cls
,
xml_object
):
return
cls
(
xml_object
.
get
(
'title'
),
xml_object
.
get
(
'
table_of_contents
_url'
))
return
cls
(
xml_object
.
get
(
'title'
),
xml_object
.
get
(
'
book
_url'
))
@property
def
table_of_contents
(
self
):
raw_table_of_contents
=
open
(
self
.
table_of_contents_url
,
'r'
)
# TODO: This will need to come from S3
table_of_contents
=
etree
.
parse
(
raw_table_of_contents
)
.
getroot
()
return
self
.
table_of_contents
def
_get_toc_from_s3
(
self
):
'''
Accesses the textbook's table of contents (default name "toc.xml") at the URL self.book_url
Returns XML tree representation of the table of contents
'''
toc_url
=
self
.
book_url
+
'toc.xml'
# Get the table of contents from S3
log
.
info
(
"Retrieving textbook table of contents from
%
s"
%
toc_url
)
try
:
r
=
requests
.
get
(
toc_url
)
except
Exception
as
err
:
msg
=
'Error
%
s: Unable to retrieve textbook table of contents at
%
s'
%
(
err
,
toc_url
)
log
.
error
(
msg
)
raise
Exception
(
msg
)
# TOC is XML. Parse it
try
:
table_of_contents
=
etree
.
fromstring
(
r
.
text
)
except
Exception
as
err
:
msg
=
'Error
%
s: Unable to parse XML for textbook table of contents at
%
s'
%
(
err
,
toc_url
)
log
.
error
(
msg
)
raise
Exception
(
msg
)
return
table_of_contents
...
...
lms/djangoapps/staticbook/views.py
View file @
de4abe30
from
django.conf
import
settings
from
django.contrib.auth.decorators
import
login_required
from
mitxmako.shortcuts
import
render_to_response
...
...
@@ -14,7 +15,7 @@ def index(request, course_id, book_index, page=0):
table_of_contents
=
textbook
.
table_of_contents
return
render_to_response
(
'staticbook.html'
,
{
'page'
:
int
(
page
),
'course'
:
course
,
{
'page'
:
int
(
page
),
'course'
:
course
,
'book_url'
:
textbook
.
book_url
,
'table_of_contents'
:
table_of_contents
,
'staff_access'
:
staff_access
})
...
...
lms/templates/staticbook.html
View file @
de4abe30
...
...
@@ -32,7 +32,7 @@ function goto_page(n) {
if
(
n
<
10
)
{
prefix
=
"00"
;
}
$
(
"#bookpage"
).
attr
(
"src"
,
"${
settings.BOOK_URL
}p"
+
prefix
+
n
+
".png"
);
$
(
"#bookpage"
).
attr
(
"src"
,
"${
book_url
}p"
+
prefix
+
n
+
".png"
);
$
.
cookie
(
"book_page"
,
n
,
{
'expires'
:
3650
,
'path'
:
'/'
});
};
...
...
@@ -113,7 +113,7 @@ $("#open_close_accordion a").click(function(){
</ul>
</nav>
<img
id=
"bookpage"
src=
"${
settings.BOOK_URL
}p${ "
%
03i
"%(
page
)
}.
png
"
>
<img
id=
"bookpage"
src=
"${
book_url
}p${ "
%
03i
"%(
page
)
}.
png
"
>
</section>
</section>
</div>
...
...
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