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
034bd730
Commit
034bd730
authored
Aug 16, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The django/mako template loader now caches mako templates by loading them from file.
parent
c4b362ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
common/lib/mitxmako/mitxmako/makoloader.py
+20
-5
common/lib/mitxmako/mitxmako/template.py
+1
-2
No files found.
common/lib/mitxmako/mitxmako/makoloader.py
View file @
034bd730
import
logging
from
django.conf
import
settings
from
django.template.base
import
TemplateDoesNotExist
from
django.template.loader
import
make_origin
,
get_template_from_string
from
django.template.loaders.filesystem
import
Loader
as
FilesystemLoader
from
django.template.loaders.app_directories
import
Loader
as
AppDirectoriesLoader
from
mitxmako.template
import
Template
import
mitxmako.middleware
log
=
logging
.
getLogger
(
__name__
)
class
MakoLoader
(
object
):
"""
...
...
@@ -18,20 +24,29 @@ class MakoLoader(object):
def
__init__
(
self
,
base_loader
):
# base_loader is an instance of a BaseLoader subclass
self
.
base_loader
=
base_loader
module_directory
=
getattr
(
settings
,
'MAKO_MODULE_DIR'
,
None
)
if
module_directory
is
None
:
log
.
warning
(
"For more caching of mako templates, set the MAKO_MODULE_DIR in settings!"
)
module_directory
=
tempfile
.
mkdtemp
()
self
.
module_directory
=
module_directory
def
__call__
(
self
,
template_name
,
template_dirs
=
None
):
return
self
.
load_template
(
template_name
,
template_dirs
)
def
load_template
(
self
,
template_name
,
template_dirs
=
None
):
source
,
display_name
=
self
.
load_template_source
(
template_name
,
template_dirs
)
source
,
file_path
=
self
.
load_template_source
(
template_name
,
template_dirs
)
if
source
.
startswith
(
"## mako
\n
"
):
# This is a mako template
template
=
Template
(
text
=
source
,
uri
=
template_name
)
template
=
Template
(
filename
=
file_path
,
module_directory
=
self
.
module_directory
,
uri
=
template_name
)
return
template
,
None
else
:
# This is a regular template
origin
=
make_origin
(
display_name
,
self
.
load_template_source
,
template_name
,
template_dirs
)
origin
=
make_origin
(
file_path
,
self
.
load_template_source
,
template_name
,
template_dirs
)
try
:
template
=
get_template_from_string
(
source
,
origin
,
template_name
)
return
template
,
None
...
...
@@ -40,7 +55,7 @@ class MakoLoader(object):
# returning the source and display name for the template we were asked to load.
# This allows for correct identification (later) of the actual template that does
# not exist.
return
source
,
display_name
return
source
,
file_path
def
load_template_source
(
self
,
template_name
,
template_dirs
=
None
):
# Just having this makes the template load as an instance, instead of a class.
...
...
common/lib/mitxmako/mitxmako/template.py
View file @
034bd730
...
...
@@ -17,8 +17,7 @@ from mako.template import Template as MakoTemplate
from
mitxmako
import
middleware
django_variables
=
[
'lookup'
,
'output_encoding'
,
'module_directory'
,
'encoding_errors'
]
django_variables
=
[
'lookup'
,
'output_encoding'
,
'encoding_errors'
]
# TODO: We should make this a Django Template subclass that simply has the MakoTemplate inside of it? (Intead of inheriting from MakoTemplate)
class
Template
(
MakoTemplate
):
...
...
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