From ee2e7a86dda2b93223716d81f78f0885f9cfe032 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 23 Feb 2022 11:10:02 +0100 Subject: Improve software inventory command Extend commands.html template to keep scope tree, and action buttons state. When in the software inventory view, there exists two options: 'update' or 'view'. Do not print raw json response from ogserver about the software inventory/profile. When vieweing the software list, print a html table using the new template: software_list.html. Do not print blank pages with plain text html error codes when something goes wrong. Instead, print an error message after redirecting to the commands view. --- ogcp/templates/actions/software.html | 4 +++- ogcp/templates/actions/software_list.html | 29 +++++++++++++++++++++++++++++ ogcp/views.py | 17 +++++++++++------ 3 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 ogcp/templates/actions/software_list.html diff --git a/ogcp/templates/actions/software.html b/ogcp/templates/actions/software.html index 71dc0ae..9393537 100644 --- a/ogcp/templates/actions/software.html +++ b/ogcp/templates/actions/software.html @@ -1,6 +1,8 @@ -{% extends 'base.html' %} +{% extends 'commands.html' %} {% import "bootstrap/wtf.html" as wtf %} +{% block nav_inventory %} active{% endblock %} +{% block nav_inventory_software %} active{% endblock %} {% block content %}

{{_('Software Inventory')}}

diff --git a/ogcp/templates/actions/software_list.html b/ogcp/templates/actions/software_list.html new file mode 100644 index 0000000..8c50edb --- /dev/null +++ b/ogcp/templates/actions/software_list.html @@ -0,0 +1,29 @@ +{% extends 'commands.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% block nav_inventory %} active{% endblock %} +{% block nav_inventory_software %} active{% endblock %} +{% block content %} + +

{{_('Software inventory')}}

+ +

{{ _('Selected client:') }} {{ form.ips.data }}

+ + + + + + + + + {% for item in software %} + + + + {% endfor %} + +
{{ _('Item') }}
{{ item }}
+ + +{% endblock %} + diff --git a/ogcp/views.py b/ogcp/views.py index c60bd08..49f5122 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -505,19 +505,24 @@ def action_software(): 'disk': int(disk), 'partition': int(partition)}) if r.status_code == requests.codes.ok: - return r.json() - + software = r.json()['software'] + scopes, clients = get_scopes(set(ips)) + return render_template('actions/software_list.html', + software=software, form=form, scopes=scopes) elif form.update.data: r = g.server.post('/software', payload={'clients': ips, 'disk': disk, 'partition': partition}) if r.status_code == requests.codes.ok: flash(_('Software profile request sent successfully'), category='info') - return redirect(url_for('commands')) - flash(_('Error processing software profile request: ({})').format(r.status), category='error') - return make_response("400 Bad Request", 400) + else: + flash(_('Error processing software profile request: ({})').format(r.status), category='error') + else: + flash(_('Error processing software profile form'), category='error') + return redirect(url_for('commands')) else: ips = parse_elements(request.args.to_dict()) + scopes, clients = get_scopes(set(ips)) if not validate_elements(ips, max_len=1): return redirect(url_for('commands')) @@ -531,7 +536,7 @@ def action_software(): f"| {PART_TYPE_CODES[part.get('code')]} " f"{FS_CODES[part.get('filesystem')]}") ) - return render_template('actions/software.html', form=form) + return render_template('actions/software.html', form=form, scopes=scopes) @app.route('/action/session', methods=['GET', 'POST']) @login_required -- cgit v1.2.3-18-g5258