diff options
| author | Alexis Métaireau <alexis@notmyidea.org> | 2018-01-14 16:52:52 +0100 |
|---|---|---|
| committer | Alexis Métaireau <alexis@notmyidea.org> | 2018-01-14 18:37:10 +0100 |
| commit | 230eafdf58c46b983936cbf4f70b712bbddfd8c9 (patch) | |
| tree | ac2a5e6de21340d1091672eff6b4ccf04114aed1 /ihatemoney/manage.py | |
| parent | 0504fd82f52317d902e85a6e448048d5ef1c58d9 (diff) | |
| download | ihatemoney-mirror-230eafdf58c46b983936cbf4f70b712bbddfd8c9.zip ihatemoney-mirror-230eafdf58c46b983936cbf4f70b712bbddfd8c9.tar.gz ihatemoney-mirror-230eafdf58c46b983936cbf4f70b712bbddfd8c9.tar.bz2 | |
Use Jinja2 strict rendering.
For this I had to create an Jinja2 explicit environment, so I put a
function in `ihatemoney.utils.create_jinja2_env(strict_rendering=False)`.
When using this environment and if `strict_rendering` is activated,
templates using undefined variables will now error out rather than
failing silently.
Diffstat (limited to 'ihatemoney/manage.py')
| -rwxr-xr-x | ihatemoney/manage.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py index 73bca57..9058b39 100755 --- a/ihatemoney/manage.py +++ b/ihatemoney/manage.py @@ -1,18 +1,17 @@ #!/usr/bin/env python import os -import pkgutil import random import sys import getpass from flask_script import Manager, Command, Option from flask_migrate import Migrate, MigrateCommand -from jinja2 import Template from werkzeug.security import generate_password_hash from ihatemoney.run import create_app from ihatemoney.models import db +from ihatemoney.utils import create_jinja_env class GeneratePasswordHash(Command): @@ -44,15 +43,14 @@ class GenerateConfig(Command): for i in range(50)]) def run(self, config_file): - template_content = pkgutil.get_data( - 'ihatemoney', - os.path.join('conf-templates/', config_file) + '.j2' - ).decode('utf-8') + env = create_jinja_env('conf-templates', strict_rendering=True) + template = env.get_template('%s.j2' % config_file) bin_path = os.path.dirname(sys.executable) + pkg_path = os.path.abspath(os.path.dirname(__file__)) - print(Template(template_content).render( - pkg_path=os.path.abspath(os.path.dirname(__file__)), + print(template.render( + pkg_path=pkg_path, bin_path=bin_path, secret_key=self.gen_secret_key(), )) |
