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
f4b37b28
Commit
f4b37b28
authored
Sep 25, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1060 from cpennington/lazy-textbooks
Make Textbooks properly lazy
parents
7bd54546
ad2da44c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
42 deletions
+11
-42
common/lib/xmodule/xmodule/course_module.py
+10
-5
common/lib/xmodule/xmodule/util/decorators.py
+0
-37
requirements/edx/base.txt
+1
-0
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
f4b37b28
...
...
@@ -6,10 +6,10 @@ from path import path # NOTE (THK): Only used for detecting presence of syllabu
import
requests
from
datetime
import
datetime
import
dateutil.parser
from
lazy
import
lazy
from
xmodule.modulestore
import
Location
from
xmodule.seq_module
import
SequenceDescriptor
,
SequenceModule
from
xmodule.util.decorators
import
lazyproperty
from
xmodule.graders
import
grader_from_conf
import
json
...
...
@@ -62,17 +62,22 @@ class Textbook(object):
def
__init__
(
self
,
title
,
book_url
):
self
.
title
=
title
self
.
book_url
=
book_url
self
.
start_page
=
int
(
self
.
table_of_contents
[
0
]
.
attrib
[
'page'
])
@lazy
def
start_page
(
self
):
return
int
(
self
.
table_of_contents
[
0
]
.
attrib
[
'page'
])
@lazy
def
end_page
(
self
):
# The last page should be the last element in the table of contents,
# but it may be nested. So recurse all the way down the last element
last_el
=
self
.
table_of_contents
[
-
1
]
while
last_el
.
getchildren
():
last_el
=
last_el
[
-
1
]
self
.
end_page
=
int
(
last_el
.
attrib
[
'page'
])
return
int
(
last_el
.
attrib
[
'page'
])
@lazy
property
@lazy
def
table_of_contents
(
self
):
"""
Accesses the textbook's table of contents (default name "toc.xml") at the URL self.book_url
...
...
@@ -738,7 +743,7 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
return
announcement
,
start
,
now
@lazy
property
@lazy
def
grading_context
(
self
):
"""
This returns a dictionary with keys necessary for quickly grading
...
...
common/lib/xmodule/xmodule/util/decorators.py
deleted
100644 → 0
View file @
7bd54546
def
lazyproperty
(
fn
):
"""
Use this decorator for lazy generation of properties that
are expensive to compute. From http://stackoverflow.com/a/3013910/86828
Example:
class Test(object):
@lazyproperty
def a(self):
print 'generating "a"'
return range(5)
Interactive Session:
>>> t = Test()
>>> t.__dict__
{}
>>> t.a
generating "a"
[0, 1, 2, 3, 4]
>>> t.__dict__
{'_lazy_a': [0, 1, 2, 3, 4]}
>>> t.a
[0, 1, 2, 3, 4]
"""
attr_name
=
'_lazy_'
+
fn
.
__name__
@property
def
_lazyprop
(
self
):
if
not
hasattr
(
self
,
attr_name
):
setattr
(
self
,
attr_name
,
fn
(
self
))
return
getattr
(
self
,
attr_name
)
return
_lazyprop
requirements/edx/base.txt
View file @
f4b37b28
...
...
@@ -34,6 +34,7 @@ feedparser==5.1.3
fs==0.4.0
GitPython==0.3.2.RC1
glob2==0.3
lazy==1.1
lxml==3.0.1
mako==0.7.3
Markdown==2.2.1
...
...
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