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
05436e59
Commit
05436e59
authored
Jun 08, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make mitxmako available to both the lms and the cms
parent
c3e730a0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
16 deletions
+13
-16
common/lib/mitxmako/README
+0
-0
common/lib/mitxmako/__init__.py
+0
-0
common/lib/mitxmako/middleware.py
+5
-5
common/lib/mitxmako/shortcuts.py
+3
-7
common/lib/mitxmako/template.py
+5
-4
No files found.
lms
/lib/mitxmako/README
→
common
/lib/mitxmako/README
View file @
05436e59
File moved
lms
/lib/mitxmako/__init__.py
→
common
/lib/mitxmako/__init__.py
View file @
05436e59
File moved
lms
/lib/mitxmako/middleware.py
→
common
/lib/mitxmako/middleware.py
View file @
05436e59
...
...
@@ -20,10 +20,10 @@ from django.conf import settings
requestcontext
=
None
lookup
=
{}
class
MakoMiddleware
(
object
):
def
__init__
(
self
):
"""Setup mako variables and lookup object"""
from
django.conf
import
settings
# Set all mako variables based on django settings
template_locations
=
settings
.
MAKO_TEMPLATES
module_directory
=
getattr
(
settings
,
'MAKO_MODULE_DIR'
,
None
)
...
...
@@ -32,17 +32,17 @@ class MakoMiddleware(object):
module_directory
=
tempfile
.
mkdtemp
()
for
location
in
template_locations
:
lookup
[
location
]
=
TemplateLookup
(
directories
=
template_locations
[
location
],
lookup
[
location
]
=
TemplateLookup
(
directories
=
template_locations
[
location
],
module_directory
=
module_directory
,
output_encoding
=
'utf-8'
,
input_encoding
=
'utf-8'
,
output_encoding
=
'utf-8'
,
input_encoding
=
'utf-8'
,
encoding_errors
=
'replace'
,
)
import
mitxmako
mitxmako
.
lookup
=
lookup
def
process_request
(
self
,
request
):
def
process_request
(
self
,
request
):
global
requestcontext
requestcontext
=
RequestContext
(
request
)
requestcontext
[
'is_secure'
]
=
request
.
is_secure
()
...
...
lms
/lib/mitxmako/shortcuts.py
→
common
/lib/mitxmako/shortcuts.py
View file @
05436e59
...
...
@@ -15,10 +15,9 @@
from
django.template
import
Context
from
django.http
import
HttpResponse
import
mitxmako.middleware
as
middleware
from
.
import
middleware
from
django.conf
import
settings
import
mitxmako.middleware
def
render_to_string
(
template_name
,
dictionary
,
context
=
None
,
namespace
=
'main'
):
context_instance
=
Context
(
dictionary
)
...
...
@@ -28,15 +27,12 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_dictionary
=
{}
context_instance
[
'settings'
]
=
settings
context_instance
[
'MITX_ROOT_URL'
]
=
settings
.
MITX_ROOT_URL
for
d
in
mi
txmako
.
mi
ddleware
.
requestcontext
:
for
d
in
middleware
.
requestcontext
:
context_dictionary
.
update
(
d
)
for
d
in
context_instance
:
context_dictionary
.
update
(
d
)
if
context
:
if
context
:
context_dictionary
.
update
(
context
)
## HACK
## We should remove this, and possible set COURSE_TITLE in the middleware from the session.
if
'COURSE_TITLE'
not
in
context_dictionary
:
context_dictionary
[
'COURSE_TITLE'
]
=
''
# fetch and render template
template
=
middleware
.
lookup
[
namespace
]
.
get_template
(
template_name
)
return
template
.
render
(
**
context_dictionary
)
...
...
lms
/lib/mitxmako/template.py
→
common
/lib/mitxmako/template.py
View file @
05436e59
...
...
@@ -14,10 +14,11 @@
from
mako.template
import
Template
as
MakoTemplate
import
middleware
from
.
import
middleware
django_variables
=
[
'lookup'
,
'template_dirs'
,
'output_encoding'
,
'module_directory'
,
'encoding_errors'
]
django_variables
=
[
'lookup'
,
'template_dirs'
,
'output_encoding'
,
'module_directory'
,
'encoding_errors'
,]
class
Template
(
MakoTemplate
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -25,4 +26,4 @@ class Template(MakoTemplate):
if
not
kwargs
.
get
(
'no_django'
,
False
):
overrides
=
dict
([(
k
,
getattr
(
middleware
,
k
,
None
),)
for
k
in
django_variables
])
kwargs
.
update
(
overrides
)
super
(
Template
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
Template
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
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