Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
9867dcec
Commit
9867dcec
authored
12 years ago
by
Victor Shnayder
Browse files
Options
Downloads
Patches
Plain Diff
Load templates at descriptor load
* instead of being lazy
parent
9d87710f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/lib/xmodule/xmodule/template_module.py
+22
-19
22 additions, 19 deletions
common/lib/xmodule/xmodule/template_module.py
with
22 additions
and
19 deletions
common/lib/xmodule/xmodule/template_module.py
+
22
−
19
View file @
9867dcec
...
...
@@ -2,7 +2,6 @@ from xmodule.x_module import XModule
from
xmodule.raw_module
import
RawDescriptor
from
lxml
import
etree
from
mako.template
import
Template
from
xmodule.util.decorators
import
lazyproperty
class
CustomTagModule
(
XModule
):
...
...
@@ -31,33 +30,37 @@ class CustomTagModule(XModule):
instance_state
=
None
,
shared_state
=
None
,
**
kwargs
):
XModule
.
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
,
shared_state
,
**
kwargs
)
self
.
html
=
definition
[
'
html
'
]
xmltree
=
etree
.
fromstring
(
self
.
definition
[
'
data
'
])
def
get_html
(
self
):
return
self
.
html
class
CustomTagDescriptor
(
RawDescriptor
):
"""
Descriptor for custom tags. Loads the template when created.
"""
module_class
=
CustomTagModule
@classmethod
def
definition_from_xml
(
cls
,
xml_object
,
system
):
definition
=
RawDescriptor
.
definition_from_xml
(
xml_object
,
system
)
# Render the template and save it.
xmltree
=
etree
.
fromstring
(
definition
[
'
data
'
])
if
'
impl
'
in
xmltree
.
attrib
:
self
.
_
template_name
=
xmltree
.
attrib
[
'
impl
'
]
template_name
=
xmltree
.
attrib
[
'
impl
'
]
else
:
# VS[compat] backwards compatibility with old nested customtag structure
child_impl
=
xmltree
.
find
(
'
impl
'
)
if
child_impl
is
not
None
:
self
.
_
template_name
=
child_impl
.
text
template_name
=
child_impl
.
text
else
:
# TODO (vshnayder): better exception type
raise
Exception
(
"
Could not find impl attribute in customtag {0}
"
.
format
(
location
))
self
.
_params
=
dict
(
xmltree
.
items
())
params
=
dict
(
xmltree
.
items
())
with
system
.
resources_fs
.
open
(
'
custom_tags/{name}
'
.
format
(
name
=
template_name
))
as
template
:
definition
[
'
html
'
]
=
Template
(
template
.
read
()).
render
(
**
params
)
@lazyproperty
def
html
(
self
):
with
self
.
system
.
filestore
.
open
(
'
custom_tags/{name}
'
.
format
(
name
=
self
.
_template_name
))
as
template
:
return
Template
(
template
.
read
()).
render
(
**
self
.
_params
)
def
get_html
(
self
):
return
self
.
html
class
CustomTagDescriptor
(
RawDescriptor
):
module_class
=
CustomTagModule
return
definition
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment