Skip to content

Commit dd75f92

Browse files
committed
Merge branch 'x33'
2 parents c8ac222 + 91ddb0e commit dd75f92

18 files changed

Lines changed: 307 additions & 25 deletions

File tree

doc/advanced.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ of how to configure Flask-Admin to inject CSP nonce values::
3737
app,
3838
content_security_policy={
3939
"default-src": "'self'",
40+
"script-src": "'self'",
41+
"style-src": "'self' 'unsafe-inline' fonts.googleapis.com ",
42+
"font-src": "'self' fonts.gstatic.com data: ",
43+
"img-src": "'self' data: ",
4044
},
4145
content_security_policy_nonce_in=["script-src", "style-src"]
4246
)

flask_admin/form/widgets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ def __init__(self, template: str) -> None:
107107
self.template = template
108108

109109
def __call__(self, field: Field, **kwargs: t.Any) -> str:
110+
admin = h.g._admin_view.admin
111+
admin_csp_nonce_attribute = (
112+
Markup(f'nonce="{admin.csp_nonce_generator()}"')
113+
if admin.csp_nonce_generator
114+
else ""
115+
)
116+
110117
kwargs.update(
111118
{
112119
"field": field,
113120
"_gettext": gettext,
114121
"_ngettext": ngettext,
115122
"h": h,
123+
"admin_csp_nonce_attribute": admin_csp_nonce_attribute,
116124
}
117125
)
118126

flask_admin/static/admin/js/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@
99
}
1010
}
1111
};
12+
13+
$('.a-unlink').on('click', function(e) {
14+
console.log('click a-unlink');
15+
e.preventDefault();
16+
});
17+
1218
})();

flask_admin/templates/bootstrap4/admin/actions.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
{% import 'admin/static.html' as admin_static with context %}
22

33
{% macro dropdown(actions, btn_class='nav-link dropdown-toggle') -%}
4-
<a class="{{ btn_class }}" data-toggle="dropdown" href="javascript:void(0)" role="button" aria-haspopup="true"
4+
<a class="{{ btn_class }} a-unlink" data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
55
aria-expanded="false">{{ _gettext('With selected') }}</a>
66
<div class="dropdown-menu">
77
{% for p in actions %}
8-
<a class="dropdown-item" href="javascript:void(0)"
9-
onclick="return modelActions.execute('{{ p[0] }}');">{{ _gettext(p[1]) }}</a>
8+
<a class="dropdown-item p-action" data-action="{{ p[0] }}">{{ _gettext(p[1]) }} </a>
109
{% endfor %}
1110
</div>
11+
12+
<script {{ admin_csp_nonce_attribute }} >
13+
14+
document.addEventListener('DOMContentLoaded', function ()
15+
{
16+
$('.p-action').on('click', function (e)
17+
{
18+
e.preventDefault();
19+
var action = $(this).data('action');
20+
modelActions.execute(action);
21+
});
22+
});
23+
</script>
1224
{% endmacro %}
1325

26+
1427
{% macro form(actions, url) %}
1528
{% if actions %}
1629
<form id="action_form" action="{{ url }}" method="POST" class="d-none">

flask_admin/templates/bootstrap4/admin/file/list.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
{% if delete_form.csrf_token is defined and delete_form.csrf_token %}
9090
{{ delete_form.csrf_token }}
9191
{% endif %}
92-
<button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\' recursively?', name=name) }}')">
92+
<button class="confirm-first"
93+
data-msg="{{ _gettext('Are you sure you want to delete \'%(name)s\' recursively?', name=name) }}">
9394
<i class="fa fa-times glyphicon glyphicon-remove"></i>
9495
</button>
9596
</form>
@@ -100,7 +101,8 @@
100101
{% if delete_form.csrf_token is defined and delete_form.csrf_token %}
101102
{{ delete_form.csrf_token }}
102103
{% endif %}
103-
<button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\'?', name=name) }}')">
104+
<button class="confirm-first"
105+
data-msg="{{ _gettext('Are you sure you want to delete \'%(name)s\' ?', name=name) }}">
104106
<i class="fa fa-trash glyphicon glyphicon-trash"></i>
105107
</button>
106108
</form>
@@ -192,4 +194,15 @@
192194
actions,
193195
actions_confirmation) }}
194196
<script {{ admin_csp_nonce_attribute }} src="{{ admin_static.url(filename='admin/js/bs4_modal.js', v='1.0.0') }}"></script>
197+
198+
199+
<script {{ admin_csp_nonce_attribute }}>
200+
201+
$('.confirm-first').on('click', function (e)
202+
{
203+
var message = $(this).data('msg');
204+
return confirm(message);
205+
});
206+
207+
</script>
195208
{% endblock %}

flask_admin/templates/bootstrap4/admin/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<!-- just enhance the readability -->
3131
<li class="{% if item.is_active(admin_view) %}active {% endif %}dropdown">
3232

33-
<a class="dropdown-toggle {% if is_main_nav %}nav-link{% else %}dropdown-item{% endif %}" data-toggle="dropdown" href="javascript:void(0)">
33+
<a class="dropdown-toggle {% if is_main_nav %}nav-link{% else %}dropdown-item{% endif %} a-unlink" data-toggle="dropdown" href="#">
3434
<!-- show icon -->
3535
{% if item.class_name %}<span class="{{ item.class_name }}"></span> {% endif %}
3636
{{ menu_icon(item) }}{{ item.name }}

flask_admin/templates/bootstrap4/admin/lib.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</li>
2828
{% else %}
2929
<li class="page-item disabled">
30-
<a class="page-link" href="javascript:void(0)">&laquo;</a>
30+
<a class="page-link a-unlink" href="#">&laquo;</a>
3131
</li>
3232
{% endif %}
3333
{% if page > 0 %}
@@ -36,14 +36,14 @@
3636
</li>
3737
{% else %}
3838
<li class="page-item disabled">
39-
<a class="page-link" href="javascript:void(0)">&lt;</a>
39+
<a class="page-link a-unlink" href="#">&lt;</a>
4040
</li>
4141
{% endif %}
4242

4343
{% for p in range(min, max) %}
4444
{% if page == p %}
4545
<li class="page-item active">
46-
<a class="page-link" href="javascript:void(0)">{{ p + 1 }}</a>
46+
<a class="page-link a-unlink" href="#">{{ p + 1 }}</a>
4747
</li>
4848
{% else %}
4949
<li class="page-item">
@@ -58,7 +58,7 @@
5858
</li>
5959
{% else %}
6060
<li class="page-item disabled">
61-
<a class="page-link" href="javascript:void(0)">&gt;</a>
61+
<a class="page-link a-unlink" href="#">&gt;</a>
6262
</li>
6363
{% endif %}
6464
{% if max < pages %}
@@ -67,7 +67,7 @@
6767
</li>
6868
{% else %}
6969
<li class="page-item disabled">
70-
<a class="page-link" href="javascript:void(0)">&raquo;</a>
70+
<a class="page-link a-unlink" href="#">&raquo;</a>
7171
</li>
7272
{% endif %}
7373
</ul>

flask_admin/templates/bootstrap4/admin/model/create.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="{{ return_url }}" class="nav-link">{{ _gettext('List') }}</a>
1515
</li>
1616
<li class="nav-item">
17-
<a href="javascript:void(0)" class="nav-link active">{{ _gettext('Create') }}</a>
17+
<a href="#" class="nav-link active a-unlink">{{ _gettext('Create') }}</a>
1818
</li>
1919
</ul>
2020
{% endblock %}

flask_admin/templates/bootstrap4/admin/model/details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</li>
1919
{%- endif -%}
2020
<li class="nav-item">
21-
<a class="nav-link active disabled" href="javascript:void(0)">{{ _gettext('Details') }}</a>
21+
<a class="nav-link active disabled a-unlink" href="#">{{ _gettext('Details') }}</a>
2222
</li>
2323
</ul>
2424
{% endblock %}

flask_admin/templates/bootstrap4/admin/model/edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</li>
2020
{%- endif -%}
2121
<li class="nav-item">
22-
<a href="javascript:void(0)" class="nav-link active">{{ _gettext('Edit') }}</a>
22+
<a href="#" class="nav-link active a-unlink">{{ _gettext('Edit') }}</a>
2323
</li>
2424
{%- if admin_view.can_view_details -%}
2525
<li class="nav-item">

0 commit comments

Comments
 (0)