From c9a2ad2b8d079c0ecca701f4c0b15390437c4843 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 16 Jul 2011 01:16:03 +0200 Subject: [PATCH] Fixed a bug in list_templates --- CHANGES | 8 ++++++++ flask/templating.py | 4 +++- tests/blueprintapp/__init__.py | 4 ++-- tests/blueprintapp/apps/admin/__init__.py | 4 +++- tests/blueprintapp/apps/frontend/__init__.py | 2 +- tests/flask_tests.py | 6 ++++++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index f9f3c82de6..4f400d8efa 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,14 @@ Relase date to be decided, codename to be chosen. - View functions can now opt out of getting the automatic OPTIONS implementation. +Version 0.7.3 +------------- + +Bugfix release, release date to be decided + +- Fixed the Jinja2 environment's list_templates method not returning the + correct names when blueprints or modules were involved. + Version 0.7.2 ------------- diff --git a/flask/templating.py b/flask/templating.py index 147f49d05e..d38d38249f 100644 --- a/flask/templating.py +++ b/flask/templating.py @@ -78,6 +78,8 @@ def _iter_loaders(self, template): pass for blueprint in self.app.blueprints.itervalues(): + if blueprint_is_module(blueprint): + continue loader = blueprint.jinja_loader if loader is not None: yield loader, template @@ -93,7 +95,7 @@ def list_templates(self): if loader is not None: for template in loader.list_templates(): prefix = '' - if not blueprint_is_module(blueprint): + if blueprint_is_module(blueprint): prefix = name + '/' result.add(prefix + template) diff --git a/tests/blueprintapp/__init__.py b/tests/blueprintapp/__init__.py index fa76807cfb..2b8ef75d9c 100644 --- a/tests/blueprintapp/__init__.py +++ b/tests/blueprintapp/__init__.py @@ -1,7 +1,7 @@ from flask import Flask app = Flask(__name__) -from moduleapp.apps.admin import admin -from moduleapp.apps.frontend import frontend +from blueprintapp.apps.admin import admin +from blueprintapp.apps.frontend import frontend app.register_blueprint(admin) app.register_blueprint(frontend) diff --git a/tests/blueprintapp/apps/admin/__init__.py b/tests/blueprintapp/apps/admin/__init__.py index fe33e3e91d..3f714d95cd 100644 --- a/tests/blueprintapp/apps/admin/__init__.py +++ b/tests/blueprintapp/apps/admin/__init__.py @@ -1,6 +1,8 @@ from flask import Blueprint, render_template -admin = Blueprint(__name__, url_prefix='/admin') +admin = Blueprint('admin', __name__, url_prefix='/admin', + template_folder='templates', + static_folder='static') @admin.route('/') diff --git a/tests/blueprintapp/apps/frontend/__init__.py b/tests/blueprintapp/apps/frontend/__init__.py index e98ff2801f..69c8666a84 100644 --- a/tests/blueprintapp/apps/frontend/__init__.py +++ b/tests/blueprintapp/apps/frontend/__init__.py @@ -1,6 +1,6 @@ from flask import Blueprint, render_template -frontend = Blueprint(__name__) +frontend = Blueprint('frontend', __name__, template_folder='templates') @frontend.route('/') diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 095f4bad10..7e00d73e67 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -1414,6 +1414,12 @@ def test_templates_and_static(self): with flask.Flask(__name__).test_request_context(): assert flask.render_template('nested/nested.txt') == 'I\'m nested' + def test_templates_list(self): + from blueprintapp import app + templates = sorted(app.jinja_env.list_templates()) + self.assertEqual(templates, ['admin/index.html', + 'frontend/index.html']) + def test_dotted_names(self): frontend = flask.Blueprint('myapp.frontend', __name__) backend = flask.Blueprint('myapp.backend', __name__)