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
b591d43d
Commit
b591d43d
authored
Aug 09, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Load templates at descriptor load
* instead of being lazy
parent
756e4057
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
common/lib/xmodule/xmodule/template_module.py
+22
-19
No files found.
common/lib/xmodule/xmodule/template_module.py
View file @
b591d43d
...
...
@@ -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
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