Skip to content

Commit

Permalink
Merge branch 'pallets-eco:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ElLorans authored Aug 8, 2024
2 parents 0055339 + c986754 commit 6b8195b
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 22 deletions.
2 changes: 2 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ New features:

And various smaller bug fixes and documentation updates.

For the full changelog, see https://github.com/pallets-eco/flask-admin/releases/tag/v2.0.0a0

1.6.1
-----

Expand Down
6 changes: 3 additions & 3 deletions examples/pymongo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_list(self, *args, **kwargs):

# Grab user names
query = {'_id': {'$in': [x['user_id'] for x in data]}}
users = db.user.find(query, fields=('name',))
users = db.user.find(query, projection=('name',))

# Contribute user names to the models
users_map = dict((x['_id'], x['name']) for x in users)
Expand All @@ -86,7 +86,7 @@ def get_list(self, *args, **kwargs):

# Contribute list of user choices to the forms
def _feed_user_choices(self, form):
users = db.user.find(fields=('name',))
users = db.user.find(projection=('name',))
form.user_id.choices = [(str(x['_id']), x['name']) for x in users]
return form

Expand All @@ -99,7 +99,7 @@ def edit_form(self, obj):
return self._feed_user_choices(form)

# Correct user_id reference before saving
def on_model_change(self, form, model):
def on_model_change(self, form, model, is_created):
user_id = model.get('user_id')
model['user_id'] = ObjectId(user_id)

Expand Down
2 changes: 2 additions & 0 deletions examples/pymongo/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
../..[pymongo]

pymongo>=4,<5
6 changes: 3 additions & 3 deletions flask_admin/templates/bootstrap4/admin/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{% macro form(actions, url) %}
{% if actions %}
<form id="action_form" action="{{ url }}" method="POST" style="display: none">
<form id="action_form" action="{{ url }}" method="POST" class="d-none">
{% if action_form.csrf_token %}
{{ action_form.csrf_token }}
{% elif csrf_token %}
Expand All @@ -27,8 +27,8 @@

{% macro script(message, actions, actions_confirmation) %}
{% if actions %}
<div id="actions-confirmation-data" style="display:none;">{{ actions_confirmation|tojson|safe }}</div>
<div id="message-data" style="display:none;">{{ message|tojson|safe }}</div>
<div id="actions-confirmation-data" class="d-none">{{ actions_confirmation|tojson|safe }}</div>
<div id="message-data" class="d-none">{{ message|tojson|safe }}</div>
<script {{ admin_csp_nonce_attribute }} src="{{ admin_static.url(filename='admin/js/actions.js', v='1.0.0') }}"></script>
{% endif %}
{% endmacro %}
5 changes: 0 additions & 5 deletions flask_admin/templates/bootstrap4/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
<link href="{{ css_url }}" rel="stylesheet" {{ admin_csp_nonce_attribute }}>
{% endfor %}
{% endif %}
<style {{ admin_csp_nonce_attribute }}>
.hide {
display: none;
}
</style>
{% endblock %}
{% block head %}
{% endblock %}
Expand Down
8 changes: 4 additions & 4 deletions flask_admin/templates/bootstrap4/admin/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
{% set prepend = kwargs.pop('prepend', None) %}
{% set append = kwargs.pop('append', None) %}
<div class="form-group {{ kwargs.get('column_class', '') }}">
<label for="{{ field.id }}" class="control-label" {% if field.widget.input_type == 'checkbox' %}style="display: block; margin-bottom: 0"{% endif %}>{{ field.label.text }}
<label for="{{ field.id }}" class="control-label {% if field.widget.input_type == 'checkbox' %}d-block mb-0{% endif %}">{{ field.label.text }}
{% if h.is_required_form_field(field) %}
<strong style="color: red">&#42;</strong>
<strong class="text-danger"">&#42;</strong>
{%- else -%}
&nbsp;
{%- endif %}
Expand Down Expand Up @@ -151,14 +151,14 @@
{%- endif -%}
{% if direct_error %}
<div class="invalid-feedback">
<ul class="form-text text-muted" {% if field.widget.input_type == 'checkbox' %}style="margin-top: 0"{% endif %}>
<ul class="form-text text-muted {% if field.widget.input_type == 'checkbox' %}mt-0{% endif %}">
{% for e in field.errors if e is string %}
<li>{{ e }}</li>
{% endfor %}
</ul>
</div>
{% elif field.description %}
<small class="form-text text-muted" {% if field.widget.input_type == 'checkbox' %}style="margin-top: 0"{% endif %}>
<small class="form-text text-muted {% if field.widget.input_type == 'checkbox' %}mt-0{% endif %}">
{{ field.description|safe }}
</small>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="pull-right">
{% if subfield.get_pk and subfield.get_pk() %}
<input type="checkbox" name="del-{{ subfield.id }}" id="del-{{ subfield.id }}" />
<label for="del-{{ subfield.id }}" style="display: inline">{{ _gettext('Delete?') }}</label>
<label for="del-{{ subfield.id }}" class="d-inline">{{ _gettext('Delete?') }}</label>
{% else %}
<a href="javascript:void(0)" value="{{ _gettext('Are you sure you want to delete this record?') }}" class="inline-remove-field"><i class="fa fa-times glyphicon glyphicon-remove"></i></a>
{% endif %}
Expand All @@ -26,7 +26,7 @@
</div>

{# template for new inline form fields #}
<div class="inline-field-template hide">
<div class="inline-field-template d-none">
{% filter forceescape %}
<div class="inline-field card card-body bg-light mb-3">
<legend>
Expand Down
2 changes: 1 addition & 1 deletion flask_admin/templates/bootstrap4/admin/model/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<input type="hidden" name="page_size" value="{{ page_size }}">
{% endif %}
<div class="pull-right">
<button type="submit" class="btn btn-primary" style="display: none">{{ _gettext('Apply') }}</button>
<button type="submit" class="btn btn-primary" class="d-none">{{ _gettext('Apply') }}</button>
{% if active_filters %}
<a href="{{ clear_search_url }}" class="btn btn-secondary">{{ _gettext('Reset Filters') }}</a>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions flask_admin/templates/bootstrap4/admin/model/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
{{ super() }}

{% if filter_groups %}
<div id="filter-groups-data" style="display:none;">{{ filter_groups|tojson|safe }}</div>
<div id="active-filters-data" style="display:none;">{{ active_filters|tojson|safe }}</div>
<div id="filter-groups-data" class="d-none">{{ filter_groups|tojson|safe }}</div>
<div id="active-filters-data" class="d-none">{{ active_filters|tojson|safe }}</div>
{% endif %}
{{ lib.form_js() }}
<script {{ admin_csp_nonce_attribute }} src="{{ admin_static.url(filename='admin/js/bs4_modal.js', v='1.0.0') }}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
{% block tail %}
{{ super() }}

<div id="execute-view-data" style="display:none;">{{ admin_view.get_url('.execute_view')|tojson|safe }}</div>
<div id="execute-view-data" class="d-none">{{ admin_view.get_url('.execute_view')|tojson|safe }}</div>
<script {{ admin_csp_nonce_attribute }} src="{{ admin_static.url(filename='admin/js/rediscli.js', v='1.0.0') }}"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion flask_admin/tests/test_csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def test_csp_nonces_injected(app, admin, nonce):
assert tag.attrs['nonce'] == nonce

styles = soup.select('style')
assert len(styles) == 1
assert len(styles) == 0
for tag in styles:
assert tag.attrs['nonce'] == nonce

0 comments on commit 6b8195b

Please sign in to comment.