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
1f34cf33
Commit
1f34cf33
authored
Aug 07, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed improvements by making the mako rendering in CustomTagModule lazy.
parent
a9d67c3e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
common/lib/xmodule/xmodule/template_module.py
+11
-5
No files found.
common/lib/xmodule/xmodule/template_module.py
View file @
1f34cf33
...
@@ -2,6 +2,7 @@ from xmodule.x_module import XModule
...
@@ -2,6 +2,7 @@ from xmodule.x_module import XModule
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.raw_module
import
RawDescriptor
from
lxml
import
etree
from
lxml
import
etree
from
mako.template
import
Template
from
mako.template
import
Template
from
util.decorators
import
lazyproperty
class
CustomTagModule
(
XModule
):
class
CustomTagModule
(
XModule
):
...
@@ -33,21 +34,26 @@ class CustomTagModule(XModule):
...
@@ -33,21 +34,26 @@ class CustomTagModule(XModule):
xmltree
=
etree
.
fromstring
(
self
.
definition
[
'data'
])
xmltree
=
etree
.
fromstring
(
self
.
definition
[
'data'
])
if
'impl'
in
xmltree
.
attrib
:
if
'impl'
in
xmltree
.
attrib
:
template_name
=
xmltree
.
attrib
[
'impl'
]
self
.
_
template_name
=
xmltree
.
attrib
[
'impl'
]
else
:
else
:
# VS[compat] backwards compatibility with old nested customtag structure
# VS[compat] backwards compatibility with old nested customtag structure
child_impl
=
xmltree
.
find
(
'impl'
)
child_impl
=
xmltree
.
find
(
'impl'
)
if
child_impl
is
not
None
:
if
child_impl
is
not
None
:
template_name
=
child_impl
.
text
self
.
_
template_name
=
child_impl
.
text
else
:
else
:
# TODO (vshnayder): better exception type
# TODO (vshnayder): better exception type
raise
Exception
(
"Could not find impl attribute in customtag {0}"
raise
Exception
(
"Could not find impl attribute in customtag {0}"
.
format
(
location
))
.
format
(
location
))
self
.
_params
=
dict
(
xmltree
.
items
())
params
=
dict
(
xmltree
.
items
())
@lazyproperty
def
html
(
self
):
with
self
.
system
.
filestore
.
open
(
with
self
.
system
.
filestore
.
open
(
'custom_tags/{name}'
.
format
(
name
=
template_name
))
as
template
:
'custom_tags/{name}'
.
format
(
name
=
self
.
_template_name
))
as
template
:
self
.
html
=
Template
(
template
.
read
())
.
render
(
**
params
)
return
Template
(
template
.
read
())
.
render
(
**
self
.
_params
)
def
get_html
(
self
):
def
get_html
(
self
):
return
self
.
html
return
self
.
html
...
...
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