Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
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
OpenEdx
problem-builder
Commits
5f739291
Commit
5f739291
authored
Nov 18, 2013
by
Xavier Antoviaque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Django templates for rendering, rename to `render_template`
parent
89639b4b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
mentoring/utils.py
+7
-4
No files found.
mentoring/utils.py
View file @
5f739291
...
...
@@ -7,6 +7,8 @@ import logging
import
os
import
pkg_resources
from
django.template
import
Context
,
Template
from
xblock.fragment
import
Fragment
...
...
@@ -25,19 +27,20 @@ def load_resource(resource_path):
resource_content
=
pkg_resources
.
resource_string
(
__name__
,
resource_path
)
return
unicode
(
resource_content
)
def
eval
_template
(
template_path
,
context
=
{}):
def
render
_template
(
template_path
,
context
=
{}):
"""
Evaluate a template by resource path, applying the provided context
"""
template
=
load_resource
(
template_path
)
return
template
.
format
(
**
context
)
template_str
=
load_resource
(
template_path
)
template
=
Template
(
template_str
)
return
template
.
render
(
Context
(
context
))
def
create_fragment
(
template_path
,
context
=
{}):
"""
Returns a new fragment, with its HTML content initialized to the evaluated template,
with the provided context
"""
html
=
eval
_template
(
template_path
,
context
=
context
)
html
=
render
_template
(
template_path
,
context
=
context
)
return
Fragment
(
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