1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

Templates cleanup

This commit is contained in:
Real-Gecko 2020-10-15 20:18:45 +06:00
parent 4f959eaee8
commit 01043ba8a8
42 changed files with 307 additions and 796 deletions

View file

@ -5,13 +5,13 @@
{% load qr_code %}
{% block title %}{% trans "User Profile" %} - {{ user }}{% endblock %}
{% block page_header %}{% trans "User Profile" %}: {{ user }}{% endblock page_header %}
{% block page_heading %}{% trans "User Profile" %}: {{ user }}{% endblock page_heading %}
{% block page_header_extra %}
{% block page_heading_extra %}
<a href="{% url 'accounts:user_instance_create' user.id %}" class="btn btn-success">
{% icon 'plus' %}
</a>
{% endblock page_header_extra %}
{% endblock page_heading_extra %}
{% block content %}
<ul class="nav nav-tabs">

View file

@ -1,175 +0,0 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Users" %}{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_user_block.html' %}
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
</div>
<h2 class="page-header">{% trans "Users" %}</h1>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not users %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any user" %}
</div>
</div>
{% else %}
<div class="col-lg-12">
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">{% trans "Username" %}</th>
<th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "Staff" %}</th>
<th scope="col">{% trans "Superuser" %}</th>
<th scope="col">{% trans "Clone" %}</th>
</tr>
</thead>
<tbody class="searchable">
{% for user in users %}
<tr class="{% if not user.is_active %}danger{% endif %}">
<td>
<a href="{% url 'accounts:account' user.id %}"><strong>{{ user.username }}</strong></a>
<a data-toggle="modal" href="#editUser{{ user.id }}" class="float-right" title="{% trans "Edit" %}">
<span class="fa fa-cog"></span>
</a>
</td>
<td>
{% if user.is_active %}
{% trans "Active" %}
{% else %}
{% trans "Blocked" %}
{% endif %}
</td>
<td>{% if user.is_staff %}<span class="fa fa-check"></span>{% endif %}</td>
<td>{% if user.is_superuser %}<span class="fa fa-check"></span>{% endif %}</td>
<td>{% if perms.instances.clone_instances %}<span class="fa fa-check"></span>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% for user in users %}
<!-- Modal Edit -->
<div class="modal fade" id="editUser{{ user.id }}" tabindex="-1" role="dialog" aria-labelledby="editUserLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post" role="form" aria-label="Edit user form">{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">{% trans "Edit user info" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="hidden" name="user_id" value="{{ user.id }}">
<input type="text" name="name" class="form-control" value="{{ user.username }}" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" name="user_pass" class="form-control" value="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Is staff" %}</label>
<div class="col-sm-2">
<input type="checkbox" name="user_is_staff" {% if user.is_staff %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Is superuser" %}</label>
<div class="col-sm-2">
<input type="checkbox" name="user_is_superuser" {% if user.is_superuser %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Can clone instances" %}</label>
<div class="col-sm-2">
<input type="checkbox" name="userattributes_can_clone_instances" {% if user.userattributes.can_clone_instances %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max instances" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_instances" class="form-control" value="{{ user.userattributes.max_instances }}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max cpus" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_cpus" class="form-control" value="{{ user.userattributes.max_cpus }}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max memory (MB)" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_memory" class="form-control" value="{{ user.userattributes.max_memory }}">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max disk size (GB)" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_disk_size" class="form-control" value="{{ user.userattributes.max_disk_size }}">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="float-left btn btn-danger" name="delete">
{% trans "Delete" %}
</button>
{% if user.is_active %}
<button type="submit" class="btn btn-warning mr-auto" name="block">
{% trans "Block" %}
</button>
{% else %}
<button type="submit" class="btn btn-success mr-auto" name="unblock">
{% trans "Unblock" %}
</button>
{% endif %}
<button type="button" class="btn btn-secondary" data-dismiss="modal">
{% trans "Close" %}
</button>
<button type="submit" class="btn btn-primary" name="edit">
{% trans "Edit" %}
</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
</div>
{% endif %}
</div>
{% endblock %}
{% block script %}
<script>
function filter_table() {
var rex = new RegExp($(this).val(), 'i');
$('.searchable tr').hide();
$('.searchable tr').filter(function () {
return rex.test($(this).text());
}).show();
}
$(document).ready(function () {
(function ($) {
$('#filter').keyup(filter_table)
}(jQuery));
});
</script>
{% endblock %}

View file

@ -1,151 +0,0 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Users" %}{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_user_block.html' %}
<h2 class="page-header">{% trans "Users" %}</h2>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not users %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any user" %}
</div>
</div>
{% else %}
{% for user in users %}
<div id="{{ user.username }}" class="col-sm-12 col-md-4">
{% if user.is_active %}
<div class="card border-success shadow">
<div class="card-header bg-success">
{% else %}
<div class="card border-secondary shadow">
<div class="card-header bg-secondary">
{% endif %}
<h5 class="my-0 card-title">
<a class="card-link text-light" href="{% url 'accounts:account' user.id %}"><strong>{{ user.username }}</strong></a>
<a class="card-link text-light float-right" data-toggle="modal" href="#editUser{{ user.id }}" title="{% trans "Edit" %}">
<span class="fa fa-cog"></span>
</a>
</h5>
</div>
<div class="card-body">
<div class="row row-cols-2">
<div class="col">
<p class="card-text font-weight-bold">{% trans "Status" %}:</p>
</div>
<div class="col">
{% if user.is_active %}
<p>{% trans "Active" %}</p>
{% else %}
<p>{% trans "Blocked" %}</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Modal Edit -->
<div class="modal fade" id="editUser{{ user.id }}" tabindex="-1" role="dialog" aria-labelledby="editUserLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Edit user info" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<form method="post" aria-label="Edit user form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="hidden" name="user_id" value="{{ user.id }}">
<input type="text" name="name" class="form-control" value="{{ user.username }}" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" name="user_pass" class="form-control" value="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Is staff" %}</label>
<div class="form-check form-check-inline col-sm-2 ml-3">
<input class="form-check-input position-static" type="checkbox" name="user_is_staff" {% if user.is_staff %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Is superuser" %}</label>
<div class="form-check form-check-inline col-sm-2 ml-3">
<input class="form-check-input position-static" type="checkbox" name="user_is_superuser" {% if user.is_superuser %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Can clone instances" %}</label>
<div class="form-check form-check-inline col-sm-2 ml-3">
<input class="form-check-input position-static" type="checkbox" name="userattributes_can_clone_instances" {% if user.userattributes.can_clone_instances %}checked{% endif %}>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max instances" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_instances" class="form-control" value="{{ user.userattributes.max_instances}}" required="True" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max cpus" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_cpus" class="form-control" value="{{ user.userattributes.max_cpus }}" required="True">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max memory (MB)" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_memory" class="form-control" value="{{ user.userattributes.max_memory}}" required="True">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Max disk size (GB)" %}</label>
<div class="col-sm-6">
<input type="text" name="userattributes_max_disk_size" class="form-control" value="{{ user.userattributes.max_disk_size }}" required="True">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger" name="delete">
{% trans "Delete" %}
</button>
{% if user.is_active %}
<button type="submit" class="btn btn-warning mr-auto" name="block">
{% trans "Block" %}
</button>
{% else %}
<button type="submit" class="btn btn-success mr-auto" name="unblock">
{% trans "Unblock" %}
</button>
{% endif %}
<button type="submit" class="btn btn-secondary" data-dismiss="modal">
{% trans "Close" %}
</button>
<button type="submit" class="btn btn-primary" name="edit">
{% trans "Edit" %}
</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
{% endif %}
</div>
{% endblock %}

View file

@ -1,38 +0,0 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#AddUser" type="button" class="btn btn-success btn-header float-right" data-toggle="modal">
<span class="fa fa-plus" aria-hidden="true"></span>
</a>
<!-- Modal pool -->
<div class="modal fade" id="AddUser" tabindex="-1" role="dialog" aria-labelledby="AddUserLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post" aria-label="Add user form">{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">{% trans "Add New User" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="name" placeholder="{% trans "john" %}" required pattern="[a-z0-9]+">
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password" class="form-control" name="password" placeholder="*******" {% if not allow_empty_password %}required{% endif %}>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
{% endif %}

View file

@ -6,7 +6,7 @@
{% block title %}{% trans "Profile" %}: {{ request.user.first_name }} {{ request.user.last_name}}{% endblock %}
{% block page_header %}{% trans "Profile" %}: {{ request.user.first_name }} {{ request.user.last_name}}{% endblock page_header %}
{% block page_heading %}{% trans "Profile" %}: {{ request.user.first_name }} {{ request.user.last_name}}{% endblock page_heading %}
{% block content %}
<ul class="nav nav-tabs">

View file

@ -0,0 +1 @@
defautl_app_config = 'admin.apps.AdminConfig'

View file

@ -1,28 +0,0 @@
{% extends "base.html" %}
{% load icons %}
{% load i18n %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
{% if create_url %}
<a class="btn btn-success float-right" href="{% url create_url %}">{% icon 'plus' %} {%trans "Create New" %}</a>
{% endif %}
<table class="table table-hover">
{% for object in object_list %}
<tr>
<td>{{ object }}
<div class="btn-group float-right">
<a class="btn btn-success" href="{% url update_url object.id %}">{% icon 'edit' %} {%trans "Edit"%}</a>
{% if extra_urls %}
{% for url in extra_urls %}
<a class="btn btn-primary" href="{% url url.0 object.id %}">{{ url.1 }}</a>
{% endfor %}
{% endif %}
<a class="btn btn-danger" href="{% url delete_url object.id %}">{% icon 'times' %} {%trans "Delete" %}</a>
</div>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View file

@ -15,7 +15,6 @@
<h1 class="page-header">{% trans "Groups" %}</h1>
</div>
</div>
{% include 'errors_block.html' %}
<div class="row">
{% if not groups %}
<div class="col-lg-12">

View file

@ -1,55 +1,48 @@
{% extends "base.html" %}
{% load i18n %}
{% load bootstrap4 %}
{% block title %}{% trans "Logs" %}{% endblock %}
{% block page_heading %}{% trans "Logs" %}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{% trans "Logs" %}</h2>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
<div class="col-lg-12">
{% if not logs %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any Logs" %}
</div>
<div class="row">
<div class="col-lg-12">
{% if not logs %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "You don't have any Logs" %}
</div>
{% else %}
{% include "paging.html" %}
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
</div>
{% else %}
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">{% trans "Date" %}</th>
<th scope="col">{% trans "User" %}</th>
<th scope="col">{% trans "Instance" %}</th>
<th scope="col">{% trans "Message" %}</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<th scope="col">#</th>
<th scope="col">{% trans "Date" %}</th>
<th scope="col">{% trans "User" %}</th>
<th scope="col">{% trans "Instance" %}</th>
<th scope="col">{% trans "Message" %}</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<td>{{ log.id }}</td>
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
<td>{{ log.user }}</td>
<td>{{ log.instance }}</td>
<td>{{ log.message }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% bootstrap_pagination logs %}
{% endif %}
</div>
<td>{{ log.id }}</td>
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
<td>{{ log.user }}</td>
<td>{{ log.instance }}</td>
<td>{{ log.message }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% bootstrap_pagination logs %}
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -3,16 +3,13 @@
{% load icons %}
{% load i18n %}
{% block title %}{% trans "User" %}{% endblock %}
{% block title %}{{ title }}{% endblock %}
{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block content %}
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{{ title }}</h2>
</div>
</div>
<div class="row">
<div class="thumbnail col-sm-10 offset-1">
<div class="card col-sm-10 offset-1">
<div class="card-body">
<form id="create-update" action="" method="post">
{% csrf_token %}
{% bootstrap_form user_form layout='horizontal' %}

View file

@ -3,20 +3,21 @@
{% load static %}
{% load common_tags %}
{% load icons %}
{% block title %}{% trans "Users" %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-12">
<a href="{% url 'admin:user_create' %}" class="btn btn-success btn-header float-right">
{% icon 'plus' %}
</a>
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans "Search" %}">
</div>
<h1 class="page-header">{% trans "Users" %}</h1>
</div>
{% block title %}{{ title }}{% endblock %}
{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block page_heading_extra %}
<a href="{% url 'admin:user_create' %}" class="btn btn-success btn-header float-right">
{% icon 'plus' %}
</a>
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans "Search" %}">
</div>
{% include 'errors_block.html' %}
{% endblock page_heading_extra %}
{% block content %}
<div class="row">
{% if not users %}
<div class="col-lg-12">

View file

@ -1,80 +1,74 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Edit Settings" %}{% endblock %}
{% block title %}{% trans "Edit Settings" %}{% endblock title %}
{% block page_heading %}{% trans "Edit Settings" %}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{% trans "Edit Settings" %}</h2>
<div class="">
<div class="col-lg-12">
<h3 class="page-header">{% trans "App Settings" %}</h3>
<form action="{% url 'set_language' %}" method="post" style="display:inline" aria-label="Edit language.name_local settings form">{% csrf_token %}
<div class="form-group row">
<input name="next" type="hidden" value="{{ redirect_to }}">
<label class="col-sm-3 col-form-label">{% trans "Language" %}</label>
<div class="col-sm-6">
<select name="language" class="form-control" onchange="this.form.submit()">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</div>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="">
<div class="col-lg-12">
<h3 class="page-header">{% trans "App Settings" %}</h3>
<form action="{% url 'set_language' %}" method="post" style="display:inline" aria-label="Edit language.name_local settings form">{% csrf_token %}
<div class="form-group row">
<input name="next" type="hidden" value="{{ redirect_to }}">
<label class="col-sm-3 col-form-label">{% trans "Language" %}</label>
<div class="col-sm-6">
<select name="language" class="form-control" onchange="this.form.submit()">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</div>
</div>
</form>
{% if request.user.is_superuser %}
<form method="post" action="" role="form" aria-label="Edit sass directory settings form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans sass_dir.name %}</label>
<div class="col-sm-6">
<input class="form-control" name="{{ sass_dir.key }}" value="{{ sass_dir.value }}" onchange="this.form.submit()" title="{% trans sass_dir.description %}"/>
</div>
</div>
</form>
<form method="post" action="" role="form" aria-label="Edit theme settings form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans bootstrap_theme.name %}</label>
<div class="col-sm-6">
<select class="form-control" name="{{ bootstrap_theme.key }}" onchange="this.form.submit()" title="{% trans bootstrap_theme.description %}">
{% for theme in themes_list %}
<option {% if bootstrap_theme.value == theme %}selected{% endif %} value="{{ theme }}">{{ theme }}</option>
</form>
{% if request.user.is_superuser %}
<form method="post" action="" role="form" aria-label="Edit sass directory settings form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans sass_dir.name %}</label>
<div class="col-sm-6">
<input class="form-control" name="{{ sass_dir.key }}" value="{{ sass_dir.value }}" onchange="this.form.submit()" title="{% trans sass_dir.description %}"/>
</div>
</div>
</form>
<form method="post" action="" role="form" aria-label="Edit theme settings form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans bootstrap_theme.name %}</label>
<div class="col-sm-6">
<select class="form-control" name="{{ bootstrap_theme.key }}" onchange="this.form.submit()" title="{% trans bootstrap_theme.description %}">
{% for theme in themes_list %}
<option {% if bootstrap_theme.value == theme %}selected{% endif %} value="{{ theme }}">{{ theme }}</option>
{% endfor %}
</select>
<span class="text-muted">{% trans "After change please full refresh page with 'Ctrl + F5' "%}</span>
</div>
</div>
</form>
{% endif %}
<h3 class="page-header">{% trans "Other Settings" %}</h3>
{% for setting in appsettings %}
<form method="post" action="" role="form" aria-label="{{setting.name}} form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans setting.name %}</label>
<div class="col-sm-6">
{% if setting.choices %}
<select class="form-control" name="{{ setting.key }}" onchange="this.form.submit()" title="{% trans setting.description %}">
{% for choice in setting.choices_as_list %}
<option {% if setting.value == choice %} selected {% endif %} value={{ choice }}>{% trans choice %}</option>
{% endfor %}
</select>
<span class="text-muted">{% trans "After change please full refresh page with 'Ctrl + F5' "%}</span>
</div>
</select>
{% else %}
<input class="form-control" name="{{ setting.key }}" value="{{ setting.value }}" title="{% trans setting.description %}" onchange="this.form.submit()"/>
{% endif%}
</div>
</form>
{% endif %}
<h3 class="page-header">{% trans "Other Settings" %}</h3>
{% for setting in appsettings %}
<form method="post" action="" role="form" aria-label="{{setting.name}} form">{% csrf_token %}
<div class="form-group row">
<label class="col-sm-3 col-form-label">{% trans setting.name %}</label>
<div class="col-sm-6">
{% if setting.choices %}
<select class="form-control" name="{{ setting.key }}" onchange="this.form.submit()" title="{% trans setting.description %}">
{% for choice in setting.choices_as_list %}
<option {% if setting.value == choice %} selected {% endif %} value={{ choice }}>{% trans choice %}</option>
{% endfor %}
</select>
{% else %}
<input class="form-control" name="{{ setting.key }}" value="{{ setting.value }}" title="{% trans setting.description %}" onchange="this.form.submit()"/>
{% endif%}
</div>
</div>
</form>
{% endfor %}
</div>
</div>
</div>
</form>
{% endfor %}
</div>
</div>
{% endblock %}

View file

@ -1,16 +1,14 @@
import sass
import os
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.decorators import login_required
import sass
from django.contrib import messages
from appsettings.models import AppSettings
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from logs.views import addlogmsg
from appsettings.models import AppSettings
@login_required
@ -19,20 +17,18 @@ def appsettings(request):
:param request:
:return:
"""
error_messages = []
main_css = "wvc-main.min.css"
sass_dir = AppSettings.objects.get(key="SASS_DIR")
bootstrap_theme = AppSettings.objects.get(key="BOOTSTRAP_THEME")
try:
themes_list = os.listdir(sass_dir.value + "/wvc-theme")
except FileNotFoundError as err:
error_messages.append(err)
messages.error(request, err)
addlogmsg(request.user.username, "", err)
# Bootstrap settings related with filesystems, because of that they are excluded from other settings
appsettings = AppSettings.objects.exclude(description__startswith="Bootstrap").order_by("name")
if request.method == 'POST':
if 'SASS_DIR' in request.POST:
try:
@ -43,7 +39,7 @@ def appsettings(request):
messages.success(request, msg)
except Exception as err:
msg = err
error_messages.append(msg)
messages.error(request, msg)
addlogmsg(request.user.username, "", msg)
return HttpResponseRedirect(request.get_full_path())
@ -58,7 +54,8 @@ def appsettings(request):
with open(sass_dir.value + "/wvc-main.scss", "w") as main:
main.write(scss_var + "\n" + scss_boot + "\n" + scss_bootswatch + "\n")
css_compressed = sass.compile(string=scss_var + "\n"+ scss_boot + "\n" + scss_bootswatch, output_style='compressed')
css_compressed = sass.compile(string=scss_var + "\n" + scss_boot + "\n" + scss_bootswatch,
output_style='compressed')
with open("static/css/" + main_css, "w") as css:
css.write(css_compressed)
@ -69,7 +66,7 @@ def appsettings(request):
messages.success(request, msg)
except Exception as err:
msg = err
error_messages.append(msg)
messages.error(request, msg)
addlogmsg(request.user.username, "", msg)
return HttpResponseRedirect(request.get_full_path())
@ -84,7 +81,7 @@ def appsettings(request):
messages.success(request, msg)
except Exception as err:
msg = err
error_messages.append(msg)
messages.error(request, msg)
addlogmsg(request.user.username, "", msg)
return HttpResponseRedirect(request.get_full_path())

View file

@ -1,8 +1,9 @@
import re
from django import forms
from django.utils.translation import gettext_lazy as _
from vrtManager.connection import CONN_SOCKET, CONN_SSH, CONN_TCP, CONN_TLS
from computes.models import Compute
from vrtManager.connection import CONN_TCP, CONN_SSH, CONN_TLS, CONN_SOCKET
from .validators import validate_hostname

View file

@ -6,9 +6,9 @@
{% block style %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
{% endblock %}
{% block page_header %}{{ compute.name }}{% endblock page_header %}
{% block page_heading %}{{ compute.name }}{% endblock page_heading %}
{% block page_header_extra %}
{% block page_heading_extra %}
<a href="{% url 'instances:create_instance_select_type' compute.id %}"
class="btn btn-success btn-header float-right">
{% icon 'plus' %}
@ -18,7 +18,7 @@
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
</div>
{% endif %}
{% endblock page_header_extra %}
{% endblock page_heading_extra %}
{% block content %}
<div class="row">

View file

@ -12,7 +12,6 @@
<h3 class="page-header">{% trans "Computes" %}</h3>
</div>
</div>
{% include 'errors_block.html' %}
<div class="row">
{% if not computes %}
<div class="col-lg-12">

View file

@ -1,42 +1,42 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load icons %}
{% block title %}{% trans "Overview" %} - {{ compute.name }}{% endblock %}
{% block page_heading %}{{ compute.name }}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{{ compute.name }}</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<span class="font-weight-bold"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</span>
<li class="breadcrumb-item">
<span class="font-weight-bold">{% icon 'dashboard' %} {% trans "Overview" %}</span>
</li>
<li class="breadcrumb-item">
<a href="{% url 'instances' compute.id %}"><i class="fa fa-server"></i> {% trans "Instances" %}</a>
<a href="{% url 'instances' compute.id %}">{% icon 'server' %} {% trans "Instances" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'storages' compute.id %}"><i class="fa fa-hdd-o"></i> {% trans "Storages" %}</a>
<a href="{% url 'storages' compute.id %}">{% icon 'hdd-o' %} {% trans "Storages" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'networks' compute.id %}"><i class="fa fa-sitemap"></i> {% trans "Networks" %}</a>
<a href="{% url 'networks' compute.id %}">{% icon 'sitemap' %} {% trans "Networks" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'interfaces' compute.id %}"><i class="fa fa-wifi"></i> {% trans "Interfaces" %}</a>
<a href="{% url 'interfaces' compute.id %}">{% icon 'wifi' %} {% trans "Interfaces" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'nwfilters' compute.id %}"><i class="fa fa-filter"></i> {% trans "NWFilters" %}</a>
<a href="{% url 'nwfilters' compute.id %}">{% icon 'filter' %} {% trans "NWFilters" %}</a>
</li>
<li class="breadcrumb-item">
<a href="{% url 'secrets' compute.id %}"><i class="fa fa-key"></i> {% trans "Secrets" %}</a>
<a href="{% url 'secrets' compute.id %}">{% icon 'key' %} {% trans "Secrets" %}</a>
</li>
</ol>
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="shadow-sm">
<h3 class="page-header">{% trans "Basic details" %}</h3>

View file

@ -6,16 +6,16 @@
{% block style %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
{% endblock %}
{% block page_header %}{% trans "Instances" %}{% endblock page_header %}
{% block page_heading %}{% trans "Instances" %}{% endblock page_heading %}
{% block page_header_extra %}
{% block page_heading_extra %}
{% if request.user.is_superuser %}
{% include 'create_inst_block.html' %}
{% endif %}
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
</div>
{% endblock page_header_extra %}
{% endblock page_heading_extra %}
{% block content %}
{% for compute in computes %}

View file

@ -1,21 +1,15 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Create new instance" %} - {% trans "Select Type" %}{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
{% blocktrans with host=compute.name %}New instance on {{ host }} {% endblocktrans %}
</h3>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'pleasewaitdialog.html' %}
{% block page_heading%}
{% blocktrans with host=compute.name %}New instance on {{ host }} {% endblocktrans %}
{% endblock page_heading %}
{% block content %}
{% include 'pleasewaitdialog.html' %}
{% if form.errors %}
{% for field in form %}

View file

@ -3,22 +3,17 @@
{% load staticfiles %}
{% load icons %}
{% block title %}{% trans "Create new instance" %}{% endblock %}
{% block style %}
<link href="{% static "css/bootstrap-multiselect.css" %}" rel="stylesheet">
{% endblock %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">
{% blocktrans with host=compute.name %}New instance on {{ host }} {% endblocktrans %}</h3>
</h3>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'pleasewaitdialog.html' %}
{% block page_heading %}
{% blocktrans with host=compute.name %}New instance on {{ host }} {% endblocktrans %}
{% endblock page_heading %}
{% block content %}
{% include 'pleasewaitdialog.html' %}
{% if form.errors %}
{% for field in form %}

View file

@ -1,14 +1,16 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load i18n %}
{% block title %}{% trans "Instance" %} - {{ instance.name }}{% endblock %}
{% block page_heading %}
{{ instance.name }}{% if instance.title %} ({{ instance.title }}){% endif %}
{% endblock page_heading %}
{% block content %}
{% include 'pleasewaitdialog.html' %}
<!-- Page Heading -->
<div>
<div>
<h3>{{ instance.name }}{% if instance.title %}&nbsp;({{ instance.title }}){% endif %}</h3>
</div>
<div>
{% if instance.status == 5 %}
<span class="badge badge-danger">{% trans "Off" %}</span>
@ -62,8 +64,6 @@
<hr>
</div>
{% include 'errors_block.html' %}
<div class="row" id="max-width-page">
<div class="container">
<div role="tabpanel">

View file

@ -4,9 +4,9 @@
{% trans "Confirm Destroy" %}
{% endblock title %}
{% block page_header %}
{% block page_heading %}
{% trans "Destroy instance" %} {{ instance }}
{% endblock page_header %}
{% endblock page_heading %}
{% block content %}
{% if request.user.is_superuser or userinstance.is_delete %}

View file

@ -1,11 +1,13 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Interface" %} - {{ iface }}{% endblock %}
{% block page_heading %}{% trans "Interface" %}: {{ iface }}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{% trans "Interface" %}: {{ iface }}</h2>
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
@ -31,9 +33,6 @@
</ol>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
<dl class="ml-3 row">

View file

@ -1,13 +1,16 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Interfaces" %} - {{ compute.name }}{% endblock %}
{% block page_heading%}{% trans "Interfaces" %} - {{ compute.name }}{% endblock page_heading %}
{% block page_heading_extra %}{% include 'create_iface_block.html' %}{% endblock page_heading_extra %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_iface_block.html' %}
<h2 class="page-header">{{ compute.name }}</h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
@ -35,9 +38,6 @@
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not ifaces_all %}

View file

@ -1,3 +1,4 @@
from django.contrib import messages
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
@ -17,7 +18,6 @@ def interfaces(request, compute_id):
"""
ifaces_all = []
error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
try:
@ -42,10 +42,10 @@ def interfaces(request, compute_id):
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())
conn.close()
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
return render(request, 'interfaces.html', locals())
@ -60,7 +60,6 @@ def interface(request, compute_id, iface):
"""
ifaces_all = []
error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
try:
@ -88,6 +87,6 @@ def interface(request, compute_id, iface):
return HttpResponseRedirect(reverse('interfaces', args=[compute_id]))
conn.close()
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
return render(request, 'interface.html', locals())

View file

@ -1,12 +0,0 @@
<div class="center-block">
{% if page > 1 %}
<a href="{% url 'showlogspage' page|add:"-1" %}">&larr;</a>
{% else %}
&nbsp;
{% endif %}
{% if has_next_page %}
<a href="{% url 'showlogspage' page|add:"1" %}">&rarr;</a>
{% else %}
&nbsp;
{% endif %}
</div>

View file

@ -1,13 +1,14 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Network" %} - {{ pool }}{% endblock %}
{% block page_heading %}{% trans "Network" %}: {{ pool }}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">{% trans "Network" %}: {{ pool }}</h2>
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
@ -34,9 +35,6 @@
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
<dl class="ml-3 row">

View file

@ -1,14 +1,13 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Networks" %} - {{ compute.name }}{% endblock %}
{% block title %}{{ compute.name }} - {% trans "Networks" %}{% endblock %}
{% block page_heading %}{{ compute.name }} - {% trans "Networks" %}{% endblock page_heading %}
{% block page_heading_extra %}{% include 'create_net_block.html' %}{% endblock page_heading_extra %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_net_block.html' %}
<h2 class="page-header">{{ compute.name }} - {% trans "Networks" %}</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav aria-label="breadcrumb">
@ -38,9 +37,6 @@
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not networks %}

View file

@ -19,8 +19,8 @@ def networks(request, compute_id):
:return:
"""
error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
errors = False
try:
conn = wvmNetworks(
@ -41,9 +41,11 @@ def networks(request, compute_id):
data = form.cleaned_data
if data['name'] in networks:
msg = _("Network pool name already in use")
error_messages.append(msg)
messages.error(request, msg)
errors = True
if data['forward'] in ['bridge', 'macvtap'] and data['bridge_name'] == '':
error_messages.append(_('Please enter bridge/dev name'))
messages.error(request, _('Please enter bridge/dev name'))
errors = True
if data['subnet']:
ipv4 = True
gateway4, netmask4, dhcp4 = network_size(data['subnet'], data['dhcp4'])
@ -51,8 +53,9 @@ def networks(request, compute_id):
ipv6 = True
gateway6, prefix6, dhcp6 = network_size(data['subnet6'], data['dhcp6'])
if prefix6 != '64':
error_messages.append(_('For libvirt, the IPv6 network prefix must be /64'))
if not error_messages:
messages.error(request, _('For libvirt, the IPv6 network prefix must be /64'))
errors = True
if not errors:
conn.create_network(
data['name'],
data['forward'],
@ -71,10 +74,10 @@ def networks(request, compute_id):
return HttpResponseRedirect(reverse('network', 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, 'networks.html', locals())
@ -88,7 +91,6 @@ def network(request, compute_id, pool):
:return:
"""
error_messages = []
compute = get_object_or_404(Compute, pk=compute_id)
try:
@ -125,7 +127,7 @@ def network(request, compute_id, pool):
xml = conn._XMLDesc(0)
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
return HttpResponseRedirect(reverse('networks', args=compute_id))
if request.method == 'POST':
@ -134,31 +136,31 @@ def network(request, compute_id, pool):
conn.start()
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'stop' in request.POST:
try:
conn.stop()
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'delete' in request.POST:
try:
conn.delete()
return HttpResponseRedirect(reverse('networks', args=[compute_id]))
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'set_autostart' in request.POST:
try:
conn.set_autostart(1)
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'unset_autostart' in request.POST:
try:
conn.set_autostart(0)
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'modify_fixed_address' in request.POST:
name = request.POST.get('name', '')
address = request.POST.get('address', '')
@ -174,9 +176,9 @@ def network(request, compute_id, pool):
messages.success(request, _(f"{family.upper()} Fixed Address Operation Completed."))
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
except ValueError as val_err:
error_messages.append(val_err)
messages.error(request, val_err)
if 'delete_fixed_address' in request.POST:
ip = request.POST.get('address', '')
family = request.POST.get('family', 'ipv4')
@ -192,7 +194,7 @@ def network(request, compute_id, pool):
messages.success(request, _(f"{family.upper()} DHCP Range is Changed."))
return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err:
error_messages.append(lib_err)
messages.error(request, lib_err)
if 'edit_network' in request.POST:
edit_xml = request.POST.get('edit_xml', '')
if edit_xml:

View file

@ -1,12 +1,14 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "NWFilters" %} - {{ compute.name }}{% endblock %}
{% block title %}{% trans "NWFilter" %}: {{ name }}{% endblock %}
{% block page_heading %}{% trans "NWFilter" %}: {{ name }}{% endblock page_heading %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">{% trans "NWFilter" %}: {{ name }}</h3>
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
@ -32,12 +34,7 @@
</ol>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
<dl class="ml-3 row">
<dt class="col-4">{% trans "UUID" %}:</dt>
<dd class="col-8">{{ uuid }}</dd>

View file

@ -1,18 +1,19 @@
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "NWFilters" %} - {{ compute.name }}{% endblock %}
{% block title %}{{ compute.name }} - {% trans "NWFilters" %}{% endblock %}
{% block page_heading %}{{ compute.name }} - {% trans "NWFilters" %}{% endblock page_heading %}
{% block page_heading_extra %}
{% include 'create_nwfilter_block.html' %}
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
</div>
{% endblock page_heading_extra %}
{% block content %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_nwfilter_block.html' %}
<div class="float-right search">
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
</div>
<h2 class="page-header">{{ compute.name }} - {% trans "NWFilters" %}</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav aria-label="breadcrumb">
@ -42,10 +43,6 @@
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
{% include 'messages_block.html' %}
<div class="row">
<div class="col-lg-12">

View file

@ -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())

View file

@ -2,15 +2,19 @@
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "Secrets" %} - {{ compute.name }}{% endblock %}
{% block style %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
{% 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 %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_secret_block.html' %}
<h2 class="page-header">{% trans "Secrets" %}</h2>
<h2 class="page-header"></h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
@ -38,9 +42,6 @@
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not secrets_all %}

View file

@ -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())

View file

@ -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 %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}"/>
{% endblock %}
{% block content %}
<!-- Page Heading -->
{% 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 %}
<div class="row">
<div class="col-lg-12">
{% include 'create_stg_vol_block.html' %}
<h2 class="page-header">{% trans "Storage" %}: {{ pool }}</h2>
<h2 class="page-header"></h2>
<ol class="breadcrumb bg-light shadow-sm">
<li class="breadcrumb-item active">
<a href="{% url 'overview' compute.id %}"><i class="fa fa-dashboard"></i> {% trans "Overview" %}</a>
@ -37,9 +39,6 @@
</ol>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<dl class="ml-3 row">
<dt class="col-6">{% trans "Pool name" %}</dt>

View file

@ -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 %}
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
{% include 'create_stg_block.html' %}
<h2 class="page-header">{{ compute.name }} - {% trans "Storages" %}</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<nav aria-label="breadcrumb">
@ -38,10 +37,6 @@
</nav>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row">
{% if not storages %}
<div class="col-lg-12">

View file

@ -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())

View file

@ -40,15 +40,16 @@
<div class"row">
<div class="col-sm-12">
<div class="float-right">
{% block page_header_extra %}
{% endblock page_header_extra %}
{% block page_heading_extra %}
{% endblock page_heading_extra %}
</div>
<h3 class="page-header">
{% block page_header %}
{% endblock page_header %}
{% block page_heading %}
{% endblock page_heading %}
</h3>
</div>
</div>
<hr>
{% bootstrap_messages %}
{% block content %}{% endblock %}
</div>

View file

@ -5,7 +5,7 @@
{% block title %}{{ title }}{% endblock %}
{% block page_header %}{{ title }}{% endblock page_header %}
{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block content %}
<div class="row">

View file

@ -5,7 +5,7 @@
{% block title %}{{ title }}{% endblock %}
{% block page_header %}{{ title }}{% endblock page_header %}
{% block page_heading %}{{ title }}{% endblock page_heading %}
{% block content %}
<div class="card">

View file

@ -1,17 +0,0 @@
{% load i18n %}
{% if error_messages %}
{% for error in error_messages %}
<!-- Error Messages -->
<div class="row">
<div class="col-lg-12">
<div class="alert alert-danger alert-dismissible" role="alert">
<strong>{% trans 'Error' %}:</strong> {{ error }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
</div>
<!-- /.row -->
{% endfor %}
{% endif %}

View file

@ -1,17 +0,0 @@
{% load i18n %}
{% if messages %}
{% for message in messages %}
<!-- Success Messages -->
<div class="row">
<div class="col-lg-12">
<div class="alert alert-success alert-dismissible" role="alert">
<strong>{% trans 'Success' %}:</strong> {{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
</div>
<!-- /.row -->
{% endfor %}
{% endif %}