mirror of https://git.48k.eu/ogcp
Start using Flask flash messages
These are used to store a message string that can be later accessed. We can use Flask flash messages to alert about any error or providing info when processing a request.multi-ogserver
parent
989dc5bd36
commit
199854f1e9
|
@ -12,6 +12,21 @@
|
|||
<body>
|
||||
{% include 'nav.html' %}
|
||||
{% block nav %}{% endblock %}
|
||||
{% block flash %}
|
||||
{% for category, message in get_flashed_messages(with_categories=True) %}
|
||||
{% if category == 'info' %}
|
||||
<div class="alert alert-info alert-dismissible fade show m-1" role="alert">
|
||||
{% elif category == 'error' %}
|
||||
<div class="alert alert-danger alert-dismissible fade show m-1" role="alert">
|
||||
{% endif %}
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="{{ _('Close') }}">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
<div id="content">{% block content %}{% endblock %}</div>
|
||||
<div id="footer">
|
||||
{% block footer %}{% endblock %}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from flask import g, render_template, url_for, redirect, request, jsonify, make_response
|
||||
from flask import (
|
||||
g, render_template, url_for, flash, redirect, request, jsonify, make_response
|
||||
)
|
||||
from ogcp.forms.action_forms import (
|
||||
WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm,
|
||||
ImageRestoreForm, ImageCreateForm, SoftwareForm
|
||||
|
@ -111,10 +113,11 @@ def action_wol():
|
|||
form = WOLForm(request.form)
|
||||
if request.method == 'POST' and form.validate():
|
||||
wol_type = form.wol_type.data
|
||||
ips = parse_ips(request.form.to_dict())
|
||||
payload = {'type': wol_type, 'clients': list(ips)}
|
||||
ips = form.ips.data.split(' ')
|
||||
payload = {'type': wol_type, 'clients': ips}
|
||||
g.server.post('/wol', payload)
|
||||
return make_response("200 OK", 200)
|
||||
flash(_('Wake On Lan request sent successfully'), category='info')
|
||||
return redirect(url_for("scopes"))
|
||||
else:
|
||||
ips = parse_ips(request.args.to_dict())
|
||||
form.ips.data = " ".join(ips)
|
||||
|
@ -312,11 +315,9 @@ def action_software():
|
|||
'disk': disk,
|
||||
'partition': partition})
|
||||
if r.status_code == requests.codes.ok:
|
||||
return make_response(f"Se generó correctamente el perfil "
|
||||
f"software de {ips[0]} D:{disk} "
|
||||
f"P:{partition}",
|
||||
200)
|
||||
|
||||
flash(_('Software profile request sent successfully'), category='info')
|
||||
return redirect(url_for("scopes"))
|
||||
flash(_(f'Error processing software profile request: ({r.status})'), category='error')
|
||||
return make_response("400 Bad Request", 400)
|
||||
else:
|
||||
ips = parse_ips(request.args.to_dict())
|
||||
|
|
Loading…
Reference in New Issue