-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirmation before deletion (#289)
- Loading branch information
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<form method="GET" action="{{ request.url }}"> | ||
<input type="hidden" name="confirm" value="1" /> | ||
<input type="submit" value="{{ action }}" class='btn btn-danger' /> <a href="{{ url_for(cancel_route) }}" class='btn btn-default'>Cancel</a> | ||
</form> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from flask import request, render_template | ||
from functools import wraps | ||
|
||
|
||
def confirm_required(action, cancel_route): | ||
def decorator(f): | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
if request.args.get("confirm"): | ||
return f(*args, **kwargs) | ||
|
||
return render_template( | ||
"confirm.html", | ||
action=action, | ||
cancel_route=cancel_route, | ||
) | ||
|
||
return decorated_function | ||
|
||
return decorator |