-
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)
Prompt user for confirmation before deleting storage service or fetch job.
- Loading branch information
Showing
4 changed files
with
67 additions
and
3 deletions.
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,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<div class="text-center align-middle" style="margin-top: 15%"> | ||
<p>{{ prompt }}</p> | ||
|
||
<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> | ||
</div> | ||
{% 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
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,27 @@ | ||
from functools import wraps | ||
|
||
from flask import abort, render_template, request | ||
|
||
|
||
def confirm_required(model, id_argument, prompt, action, cancel_route): | ||
def decorator(f): | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
instance = model.query.get(kwargs[id_argument]) | ||
|
||
if not instance: | ||
abort(404) | ||
|
||
if request.args.get("confirm"): | ||
return f(*args, **kwargs) | ||
|
||
return render_template( | ||
"confirm.html", | ||
prompt=prompt, | ||
action=action, | ||
cancel_route=cancel_route, | ||
) | ||
|
||
return decorated_function | ||
|
||
return decorator |