2022-05-04 13:46:52 +01:00
|
|
|
from flask import Response, render_template, flash, redirect, url_for
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
from app.models import AbstractResource
|
|
|
|
from app.portal.forms import LifecycleForm
|
|
|
|
|
|
|
|
|
|
|
|
def response_404(message: str):
|
|
|
|
return Response(render_template("error.html.j2",
|
|
|
|
header="404 Not Found",
|
|
|
|
message=message))
|
|
|
|
|
|
|
|
|
|
|
|
def view_lifecycle(*,
|
|
|
|
header: str,
|
|
|
|
message: str,
|
|
|
|
success_message: str,
|
|
|
|
success_view: str,
|
|
|
|
section: str,
|
|
|
|
resource: AbstractResource,
|
|
|
|
action: str):
|
|
|
|
form = LifecycleForm()
|
2022-05-08 17:20:04 +01:00
|
|
|
if action == "destroy":
|
|
|
|
form.submit.render_kw = {"class": "btn btn-danger"}
|
|
|
|
elif action == "deprecate":
|
|
|
|
form.submit.render_kw = {"class": "btn btn-warning"}
|
|
|
|
elif action == "kick":
|
|
|
|
form.submit.render_kw = {"class": "btn btn-success"}
|
2022-05-04 13:46:52 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
if action == "destroy":
|
|
|
|
resource.destroy()
|
|
|
|
elif action == "deprecate":
|
|
|
|
resource.deprecate(reason="manual")
|
2022-05-08 17:20:04 +01:00
|
|
|
elif action == "kick":
|
|
|
|
resource.kick()
|
2022-05-04 13:46:52 +01:00
|
|
|
else:
|
|
|
|
flash("Unknown action")
|
|
|
|
return redirect(url_for("portal.portal_home"))
|
|
|
|
db.session.commit()
|
|
|
|
flash(success_message, "success")
|
|
|
|
return redirect(url_for(success_view))
|
|
|
|
return render_template("lifecycle.html.j2",
|
|
|
|
header=header,
|
|
|
|
message=message,
|
|
|
|
section=section,
|
2022-05-04 14:03:04 +01:00
|
|
|
form=form)
|