diff --git a/nwfilters/views.py b/nwfilters/views.py
index 6fdef30..3ac9407 100644
--- a/nwfilters/views.py
+++ b/nwfilters/views.py
@@ -1,11 +1,10 @@
-from django.http import HttpResponseRedirect
-from django.shortcuts import get_object_or_404, render
-from django.urls import reverse
-from django.utils.translation import gettext_lazy as _
-from libvirt import libvirtError
-
from admin.decorators import superuser_only
from computes.models import Compute
+from django.contrib import messages
+from django.http import HttpResponseRedirect
+from django.shortcuts import get_object_or_404, render
+from django.utils.translation import gettext_lazy as _
+from libvirt import libvirtError
from logs.views import addlogmsg
from vrtManager import util
from vrtManager.instance import wvmInstance, wvmInstances
@@ -20,7 +19,6 @@ def nwfilters(request, compute_id):
:return:
"""
- error_messages = []
nwfilters_all = []
compute = get_object_or_404(Compute, pk=compute_id)
@@ -51,7 +49,7 @@ def nwfilters(request, compute_id):
conn.create_nwfilter(xml)
addlogmsg(request.user.username, compute.hostname, msg)
except libvirtError as lib_err:
- error_messages.append(lib_err)
+ messages.error(request, lib_err)
addlogmsg(request.user.username, compute.hostname, lib_err)
if 'del_nwfilter' in request.POST:
@@ -69,7 +67,7 @@ def nwfilters(request, compute_id):
if name in dom_filterrefs:
in_use = True
msg = _(f"NWFilter is in use by {inst}. Cannot be deleted.")
- error_messages.append(msg)
+ messages.error(request, msg)
addlogmsg(request.user.username, compute.hostname, msg)
i_conn.close()
break
@@ -93,16 +91,15 @@ def nwfilters(request, compute_id):
conn.close()
except libvirtError as lib_err:
- error_messages.append(lib_err)
+ messages.error(request, lib_err)
addlogmsg(request.user.username, compute.hostname, lib_err)
except Exception as err:
- error_messages.append(err)
+ messages.error(request, err)
addlogmsg(request.user.username, compute.hostname, err)
return render(request, 'nwfilters.html', {
- 'error_messages': error_messages,
'nwfilters': nwfilters_all,
- 'compute': compute
+ 'compute': compute,
})
@@ -113,7 +110,6 @@ def nwfilter(request, compute_id, nwfltr):
:param nwfltr:
:return:
"""
- error_messages = []
nwfilters_all = []
compute = get_object_or_404(Compute, pk=compute_id)
@@ -194,8 +190,8 @@ def nwfilter(request, compute_id, nwfltr):
conn.close()
nwfilter.close()
except libvirtError as lib_err:
- error_messages.append(lib_err)
+ messages.error(request, lib_err)
except Exception as error_msg:
- error_messages.append(error_msg)
+ messages.error(request, error_msg)
return render(request, 'nwfilter.html', locals())
diff --git a/secrets/templates/secrets.html b/secrets/templates/secrets.html
index a3274a0..b5e21ba 100644
--- a/secrets/templates/secrets.html
+++ b/secrets/templates/secrets.html
@@ -2,15 +2,19 @@
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Secrets" %} - {{ compute.name }}{% endblock %}
+
{% block style %}
{% endblock %}
+
+{% block page_heading %}{{ compute }} - {% trans "Secrets" %}{% endblock page_heading %}
+
+{% block page_heading_extra %}{% include 'create_secret_block.html' %}{% endblock page_heading_extra %}
+
{% block content %}
-
- {% include 'create_secret_block.html' %}
-
+
@@ -38,9 +42,6 @@
-
-
- {% include 'errors_block.html' %}
{% if not secrets_all %}
diff --git a/secrets/views.py b/secrets/views.py
index 9b47f18..3788d87 100644
--- a/secrets/views.py
+++ b/secrets/views.py
@@ -1,17 +1,12 @@
-
-from django.http import HttpResponseRedirect
-from django.shortcuts import get_object_or_404, render
-from django.urls import reverse
-from libvirt import libvirtError
-from libvirt import (VIR_SECRET_USAGE_TYPE_NONE,
- VIR_SECRET_USAGE_TYPE_CEPH,
- VIR_SECRET_USAGE_TYPE_TLS,
- VIR_SECRET_USAGE_TYPE_VOLUME,
- VIR_SECRET_USAGE_TYPE_ISCSI)
+from secrets.forms import AddSecret
from admin.decorators import superuser_only
from computes.models import Compute
-from secrets.forms import AddSecret
+from django.contrib import messages
+from django.http import HttpResponseRedirect
+from django.shortcuts import get_object_or_404, render
+from libvirt import (VIR_SECRET_USAGE_TYPE_CEPH, VIR_SECRET_USAGE_TYPE_ISCSI, VIR_SECRET_USAGE_TYPE_NONE,
+ VIR_SECRET_USAGE_TYPE_TLS, VIR_SECRET_USAGE_TYPE_VOLUME, libvirtError)
from vrtManager.secrets import wvmSecrets
@@ -24,7 +19,6 @@ def secrets(request, compute_id):
"""
secrets_all = []
- error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
secret_usage_types = {
VIR_SECRET_USAGE_TYPE_NONE: "none",
@@ -59,11 +53,12 @@ def secrets(request, compute_id):
data['ephemeral'],
data['private'],
data['usage_type'],
- data['data'])
+ data['data'],
+ )
return HttpResponseRedirect(request.get_full_path())
else:
for msg_err in form.errors.values():
- error_messages.append(msg_err.as_text())
+ messages.error(request, msg_err.as_text())
if 'delete' in request.POST:
uuid = request.POST.get('uuid', '')
conn.delete_secret(uuid)
@@ -74,9 +69,9 @@ def secrets(request, compute_id):
try:
conn.set_secret_value(uuid, value)
except Exception as err:
- error_messages.append(err)
+ messages.error(request, err)
return HttpResponseRedirect(request.get_full_path())
except libvirtError as err:
- error_messages.append(err)
+ messages.error(request, err)
return render(request, 'secrets.html', locals())
diff --git a/storages/templates/storage.html b/storages/templates/storage.html
index b23aa04..cec96b5 100644
--- a/storages/templates/storage.html
+++ b/storages/templates/storage.html
@@ -1,17 +1,19 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
-{% block title %}{% trans "Storage" %} - {{ pool }}{% endblock %}
+{% block title %}{{ compute }} - {% trans "Storage" %}: {{ pool }}{% endblock %}
{% block style %}
{% endblock %}
-{% block content %}
-
+{% block page_heading %}{{ compute }} - {% trans "Storage" %}: {{ pool }}{% endblock page_heading %}
+
+{% block page_heading_extra %}{% include 'create_stg_vol_block.html' %}{% endblock page_heading_extra %}
+
+{% block content %}
-
-
- {% include 'errors_block.html' %}
{% trans "Pool name" %}
diff --git a/storages/templates/storages.html b/storages/templates/storages.html
index dba6770..fddcc58 100644
--- a/storages/templates/storages.html
+++ b/storages/templates/storages.html
@@ -1,14 +1,13 @@
{% extends "base.html" %}
{% load i18n %}
-{% block title %}{% trans "Storages" %} - {{ compute.name }}{% endblock %}
+
+{% block title %}{{ compute.name }} - {% trans "Storages" %}{% endblock %}
+
+{% block page_heading %}{{ compute.name }} - {% trans "Storages" %}{% endblock page_heading %}
+
+{% block page_heading_extra %}{% include 'create_stg_block.html' %}{% endblock page_heading_extra %}
+
{% block content %}
-
-
-
- {% include 'create_stg_block.html' %}
-
-
-
-
-
- {% include 'errors_block.html' %}
-
{% if not storages %}
diff --git a/storages/views.py b/storages/views.py
index 2d70be2..b3ee0b1 100644
--- a/storages/views.py
+++ b/storages/views.py
@@ -23,8 +23,8 @@ def storages(request, compute_id):
:return:
"""
- error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
+ errors = False
try:
conn = wvmStorages(compute.hostname, compute.login, compute.password, compute.type)
@@ -38,15 +38,18 @@ def storages(request, compute_id):
data = form.cleaned_data
if data['name'] in storages:
msg = _("Pool name already use")
- error_messages.append(msg)
+ messages.error(request, msg)
+ errors = True
if data['stg_type'] == 'rbd':
if not data['secret']:
msg = _("You need create secret for pool")
- error_messages.append(msg)
+ messages.error(request, msg)
+ errors = True
if not data['ceph_pool'] and not data['ceph_host'] and not data['ceph_user']:
msg = _("You need input all fields for creating ceph pool")
- error_messages.append(msg)
- if not error_messages:
+ messages.error(request, msg)
+ errors = True
+ if not errors:
if data['stg_type'] == 'rbd':
conn.create_storage_ceph(data['stg_type'], data['name'], data['ceph_pool'], data['ceph_host'],
data['ceph_user'], data['secret'])
@@ -58,10 +61,10 @@ def storages(request, compute_id):
return HttpResponseRedirect(reverse('storage', args=[compute_id, data['name']]))
else:
for msg_err in form.errors.values():
- error_messages.append(msg_err.as_text())
+ messages.error(request, msg_err.as_text())
conn.close()
except libvirtError as lib_err:
- error_messages.append(lib_err)
+ messages.error(request, lib_err)
return render(request, 'storages.html', locals())
diff --git a/templates/base.html b/templates/base.html
index 02a17e1..0d71065 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -40,15 +40,16 @@
- {% block page_header_extra %}
- {% endblock page_header_extra %}
+ {% block page_heading_extra %}
+ {% endblock page_heading_extra %}
+
{% bootstrap_messages %}
{% block content %}{% endblock %}
diff --git a/templates/common/confirm_delete.html b/templates/common/confirm_delete.html
index 6f4a42c..fc22c52 100644
--- a/templates/common/confirm_delete.html
+++ b/templates/common/confirm_delete.html
@@ -5,7 +5,7 @@
{% block title %}{{ title }}{% endblock %}
-{% block page_header %}{{ title }}{% endblock page_header %}
+{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block content %}
diff --git a/templates/common/form.html b/templates/common/form.html
index 0e5a000..6c58af0 100644
--- a/templates/common/form.html
+++ b/templates/common/form.html
@@ -5,7 +5,7 @@
{% block title %}{{ title }}{% endblock %}
-{% block page_header %}{{ title }}{% endblock page_header %}
+{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block content %}
diff --git a/templates/errors_block.html b/templates/errors_block.html
deleted file mode 100644
index 2fb6c61..0000000
--- a/templates/errors_block.html
+++ /dev/null
@@ -1,17 +0,0 @@
-{% load i18n %}
-{% if error_messages %}
- {% for error in error_messages %}
-
-
-
-
- {% trans 'Error' %}: {{ error }}
-
- ×
-
-
-
-
-
- {% endfor %}
-{% endif %}
\ No newline at end of file
diff --git a/templates/messages_block.html b/templates/messages_block.html
deleted file mode 100644
index 95773cf..0000000
--- a/templates/messages_block.html
+++ /dev/null
@@ -1,17 +0,0 @@
-{% load i18n %}
-{% if messages %}
- {% for message in messages %}
-
-
-
-
- {% trans 'Success' %}: {{ message }}
-
- ×
-
-
-
-
-
- {% endfor %}
-{% endif %}
\ No newline at end of file