Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#279] Make bp_includes.lib.basehandler share jinja2_factory with bp_…
…includes.lib.error_handler.
- Loading branch information
Showing
3 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import webapp2 | ||
from webapp2_extras import jinja2 | ||
from webapp2_extras import sessions | ||
from bp_includes.lib import utils | ||
|
||
def generate_csrf_token(): | ||
session = sessions.get_store().get_session() | ||
if '_csrf_token' not in session: | ||
session['_csrf_token'] = utils.random_string() | ||
return session['_csrf_token'] | ||
|
||
def jinja2_factory(app): | ||
j = jinja2.Jinja2(app) | ||
j.environment.filters.update({ | ||
# Set filters. | ||
# ... | ||
}) | ||
j.environment.globals.update({ | ||
# Set global variables. | ||
'csrf_token': generate_csrf_token, | ||
'uri_for': webapp2.uri_for, | ||
'getattr': getattr, | ||
}) | ||
j.environment.tests.update({ | ||
# Set test. | ||
# ... | ||
}) | ||
return j |