diff --git a/doc/changelog.rst b/doc/changelog.rst index 526a694a8..4feace7a2 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +2.0.0a3 +------- + +Fixes: + +* Jinja templates can now be loaded in StrictUndefined mode. + 2.0.0a2 ------- diff --git a/examples/sqla/app.py b/examples/sqla/app.py index 54aa23430..2a8c676b8 100644 --- a/examples/sqla/app.py +++ b/examples/sqla/app.py @@ -3,6 +3,7 @@ from admin import app from admin.data import build_sample_db +from jinja2 import StrictUndefined # Build a sample db on the fly, if one does not exist yet. app_dir = op.join(op.realpath(os.path.dirname(__file__)), "admin") @@ -13,4 +14,5 @@ if __name__ == "__main__": # Start app + app.jinja_env.undefined = StrictUndefined app.run(debug=True) diff --git a/flask_admin/base.py b/flask_admin/base.py index 760b73fe0..e07d7d966 100644 --- a/flask_admin/base.py +++ b/flask_admin/base.py @@ -146,6 +146,12 @@ def index(self): ) """ + extra_css: list[str] = [] + """Extra CSS files to include in the page""" + + extra_js: list[str] = [] + """Extra JavaScript files to include in the page""" + @property def _template_args(self): """ diff --git a/flask_admin/templates/bootstrap4/admin/actions.html b/flask_admin/templates/bootstrap4/admin/actions.html index 6884a095a..89899089b 100644 --- a/flask_admin/templates/bootstrap4/admin/actions.html +++ b/flask_admin/templates/bootstrap4/admin/actions.html @@ -14,12 +14,16 @@ {% macro form(actions, url) %} {% if actions %}
- {% if action_form.csrf_token %} + {% if action_form.csrf_token is defined and action_form.csrf_token %} {{ action_form.csrf_token }} - {% elif csrf_token %} + {% elif csrf_token is defined and csrf_token %} {% endif %} - {{ action_form.url(value=return_url) }} + {% if return_url is defined and return_url %} + {{ action_form.url(value=return_url) }} + {% else %} + {{ action_form.url() }} + {% endif %} {{ action_form.action() }}
{% endif %} diff --git a/flask_admin/templates/bootstrap4/admin/file/list.html b/flask_admin/templates/bootstrap4/admin/file/list.html index ca9ce77c0..dc9be0191 100644 --- a/flask_admin/templates/bootstrap4/admin/file/list.html +++ b/flask_admin/templates/bootstrap4/admin/file/list.html @@ -86,7 +86,9 @@ {% if name != '..' and admin_view.can_delete_dirs %}
{{ delete_form.path(value=path) }} + {% if delete_form.csrf_token is defined and delete_form.csrf_token %} {{ delete_form.csrf_token }} + {% endif %} @@ -95,7 +97,9 @@ {% else %} {{ delete_form.path(value=path) }} + {% if delete_form.csrf_token is defined and delete_form.csrf_token %} {{ delete_form.csrf_token }} + {% endif %} diff --git a/flask_admin/templates/bootstrap4/admin/lib.html b/flask_admin/templates/bootstrap4/admin/lib.html index 2358bbc28..382647c40 100644 --- a/flask_admin/templates/bootstrap4/admin/lib.html +++ b/flask_admin/templates/bootstrap4/admin/lib.html @@ -120,7 +120,7 @@ {% set prepend = kwargs.pop('prepend', None) %} {% set append = kwargs.pop('append', None) %}
-
{%- endif -%} {% endif %} - {% if field.widget.input_type == 'checkbox' %} + {% if field.widget.input_type is defined and field.widget.input_type == 'checkbox' %} {% set _class = kwargs.setdefault('class', '') %} - {% elif field.widget.input_type == 'file' %} + {% elif field.widget.input_type is defined and field.widget.input_type == 'file' %} {% set _class = kwargs.setdefault('class', 'form-control-file') %} {% else %} {% set _class = kwargs.setdefault('class', 'form-control') %} @@ -179,10 +179,10 @@

{{ text }}

{% if form.hidden_tag is defined %} {{ form.hidden_tag() }} {% else %} - {% if csrf_token %} + {% if csrf_token is defined and csrf_token %} {% endif %} - {% for f in form if f.widget.input_type == 'hidden' %} + {% for f in form if f.widget.input_type is defined and f.widget.input_type == 'hidden' %} {{ f }} {% endfor %} {% endif %} @@ -192,7 +192,7 @@

{{ text }}

{{ r(form, form_opts=form_opts) }} {% endfor %} {% else %} - {% for f in form if f.widget.input_type != 'hidden' %} + {% for f in form if f.widget.input_type is undefined or f.widget.input_type != 'hidden' %} {% if form_opts %} {% set kwargs = form_opts.widget_args.get(f.short_name, {}) %} {% else %} @@ -228,7 +228,7 @@

{{ text }}

{% if extra %} {{ extra }} {% endif %} - {% if cancel_url %} + {% if cancel_url is defined and cancel_url %} {{ _gettext('Cancel') }} {% endif %} @@ -247,31 +247,31 @@

{{ text }}

- {% if config.FLASK_ADMIN_MAPS %} + {% if config.FLASK_ADMIN_MAPS is defined and config.FLASK_ADMIN_MAPS %} {% endif %} - {% if editable_columns %} + {% if editable_columns is defined and editable_columns %} {% endif %} {% endmacro %} {% macro form_js() %} - {% if config.FLASK_ADMIN_MAPS %} + {% if config.FLASK_ADMIN_MAPS is defined and config.FLASK_ADMIN_MAPS %} - {% if config.FLASK_ADMIN_MAPS_SEARCH %} + {% if config.FLASK_ADMIN_MAPS_SEARCH is defined and config.FLASK_ADMIN_MAPS_SEARCH %} @@ -279,7 +279,7 @@

{{ text }}

{% endif %} {% endif %} - {% if editable_columns %} + {% if editable_columns is defined and editable_columns %} {% endif %} diff --git a/flask_admin/templates/bootstrap4/admin/model/list.html b/flask_admin/templates/bootstrap4/admin/model/list.html index 7609075bc..b7825ebe3 100644 --- a/flask_admin/templates/bootstrap4/admin/model/list.html +++ b/flask_admin/templates/bootstrap4/admin/model/list.html @@ -135,9 +135,9 @@ {% if admin_view.is_editable(c) %} {% set form = list_forms[get_pk_value(row)] %} - {% if form.csrf_token %} + {% if form.csrf_token is defined and form.csrf_token %} {{ form[c](pk=get_pk_value(row), display_value=get_value(row, c), csrf=form.csrf_token._value()) }} - {% elif csrf_token %} + {% elif csrf_token is defined and csrf_token %} {{ form[c](pk=get_pk_value(row), display_value=get_value(row, c), csrf=csrf_token()) }} {% else %} {{ form[c](pk=get_pk_value(row), display_value=get_value(row, c)) }} diff --git a/flask_admin/templates/bootstrap4/admin/model/row_actions.html b/flask_admin/templates/bootstrap4/admin/model/row_actions.html index 105b5fdf5..1fbfc5a56 100644 --- a/flask_admin/templates/bootstrap4/admin/model/row_actions.html +++ b/flask_admin/templates/bootstrap4/admin/model/row_actions.html @@ -26,9 +26,9 @@ {{ delete_form.id(value=get_pk_value(row)) }} {{ delete_form.url(value=return_url) }} - {% if delete_form.csrf_token %} + {% if delete_form.csrf_token is defined and delete_form.csrf_token %} {{ delete_form.csrf_token }} - {% elif csrf_token %} + {% elif csrf_token is defined and csrf_token %} {% endif %}