mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
Add new forms and templates
This commit is contained in:
parent
00b4d751ad
commit
ed2b28c25e
12 changed files with 263 additions and 25 deletions
|
@ -3,6 +3,7 @@ from django.core.urlresolvers import reverse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from computes.models import Compute
|
from computes.models import Compute
|
||||||
from instances.models import Instance
|
from instances.models import Instance
|
||||||
|
from users.models import UserInstance
|
||||||
from computes.forms import ComputeAddTcpForm, ComputeAddSshForm, ComputeEditHostForm, ComputeAddTlsForm, ComputeAddSocketForm
|
from computes.forms import ComputeAddTcpForm, ComputeAddSshForm, ComputeEditHostForm, ComputeAddTlsForm, ComputeAddSocketForm
|
||||||
from vrtManager.hostdetails import wvmHostDetails
|
from vrtManager.hostdetails import wvmHostDetails
|
||||||
from vrtManager.connection import CONN_SSH, CONN_TCP, CONN_TLS, CONN_SOCKET, connection_manager
|
from vrtManager.connection import CONN_SSH, CONN_TCP, CONN_TLS, CONN_SOCKET, connection_manager
|
||||||
|
@ -37,12 +38,17 @@ def computes(request):
|
||||||
})
|
})
|
||||||
return compute_data
|
return compute_data
|
||||||
|
|
||||||
|
error_messages = []
|
||||||
computes = Compute.objects.filter()
|
computes = Compute.objects.filter()
|
||||||
computes_info = get_hosts_status(computes)
|
computes_info = get_hosts_status(computes)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'host_del' in request.POST:
|
if 'host_del' in request.POST:
|
||||||
compute_id = request.POST.get('host_id', '')
|
compute_id = request.POST.get('host_id', '')
|
||||||
|
try:
|
||||||
|
del_user_inst_on_host = UserInstance.objects.filter(compute_id=compute_id)
|
||||||
|
del_user_inst_on_host.save()
|
||||||
|
finally:
|
||||||
try:
|
try:
|
||||||
del_inst_on_host = Instance.objects.filter(compute_id=compute_id)
|
del_inst_on_host = Instance.objects.filter(compute_id=compute_id)
|
||||||
del_inst_on_host.delete()
|
del_inst_on_host.delete()
|
||||||
|
@ -61,6 +67,9 @@ def computes(request):
|
||||||
password=data['password'])
|
password=data['password'])
|
||||||
new_tcp_host.save()
|
new_tcp_host.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'host_ssh_add' in request.POST:
|
if 'host_ssh_add' in request.POST:
|
||||||
form = ComputeAddSshForm(request.POST)
|
form = ComputeAddSshForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -71,6 +80,9 @@ def computes(request):
|
||||||
login=data['login'])
|
login=data['login'])
|
||||||
new_ssh_host.save()
|
new_ssh_host.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'host_tls_add' in request.POST:
|
if 'host_tls_add' in request.POST:
|
||||||
form = ComputeAddTlsForm(request.POST)
|
form = ComputeAddTlsForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -82,6 +94,9 @@ def computes(request):
|
||||||
password=data['password'])
|
password=data['password'])
|
||||||
new_tls_host.save()
|
new_tls_host.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'host_socket_add' in request.POST:
|
if 'host_socket_add' in request.POST:
|
||||||
form = ComputeAddSocketForm(request.POST)
|
form = ComputeAddSocketForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -93,6 +108,9 @@ def computes(request):
|
||||||
password='')
|
password='')
|
||||||
new_socket_host.save()
|
new_socket_host.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'host_edit' in request.POST:
|
if 'host_edit' in request.POST:
|
||||||
form = ComputeEditHostForm(request.POST)
|
form = ComputeEditHostForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
@ -104,7 +122,9 @@ def computes(request):
|
||||||
compute_edit.password = data['password']
|
compute_edit.password = data['password']
|
||||||
compute_edit.save()
|
compute_edit.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
return render(request, 'computes.html', locals())
|
return render(request, 'computes.html', locals())
|
||||||
|
|
||||||
def overview(request, compute_id):
|
def overview(request, compute_id):
|
||||||
|
|
|
@ -62,7 +62,6 @@ def instances(request):
|
||||||
check_uuid.save()
|
check_uuid.save()
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
print 'Error'
|
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
|
||||||
return render(request, 'instances.html', locals())
|
return render(request, 'instances.html', locals())
|
||||||
|
|
|
@ -47,6 +47,9 @@ def interfaces(request, compute_id):
|
||||||
data['ipv6_type'], data['ipv6_addr'], data['ipv6_gw'],
|
data['ipv6_type'], data['ipv6_addr'], data['ipv6_gw'],
|
||||||
data['stp'], data['delay'])
|
data['stp'], data['delay'])
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
|
|
@ -50,6 +50,9 @@ def networks(request, compute_id):
|
||||||
conn.create_network(data['name'], data['forward'], gateway, netmask,
|
conn.create_network(data['name'], data['forward'], gateway, netmask,
|
||||||
dhcp, data['bridge_name'], data['openvswitch'], data['fixed'])
|
dhcp, data['bridge_name'], data['openvswitch'], data['fixed'])
|
||||||
return HttpResponseRedirect(reverse('network', args=[compute_id, data['name']]))
|
return HttpResponseRedirect(reverse('network', args=[compute_id, data['name']]))
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
|
|
@ -47,6 +47,9 @@ def secrets(request, compute_id):
|
||||||
data = form.cleaned_data
|
data = form.cleaned_data
|
||||||
conn.create_secret(data['ephemeral'], data['private'], data['usage_type'], data['data'])
|
conn.create_secret(data['ephemeral'], data['private'], data['usage_type'], data['data'])
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'delete' in request.POST:
|
if 'delete' in request.POST:
|
||||||
uuid = request.POST.get('uuid', '')
|
uuid = request.POST.get('uuid', '')
|
||||||
conn.delete_secret(uuid)
|
conn.delete_secret(uuid)
|
||||||
|
|
|
@ -58,6 +58,9 @@ def storages(request, compute_id):
|
||||||
else:
|
else:
|
||||||
conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
|
conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
|
||||||
return HttpResponseRedirect(reverse('storage', args=[compute_id, data['name']]))
|
return HttpResponseRedirect(reverse('storage', args=[compute_id, data['name']]))
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
@ -155,6 +158,9 @@ def storage(request, compute_id, pool):
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
if 'del_volume' in request.POST:
|
if 'del_volume' in request.POST:
|
||||||
volname = request.POST.get('volname', '')
|
volname = request.POST.get('volname', '')
|
||||||
try:
|
try:
|
||||||
|
@ -191,6 +197,9 @@ def storage(request, compute_id, pool):
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return render(request, 'storage.html', locals())
|
return render(request, 'storage.html', locals())
|
||||||
|
|
|
@ -1,5 +1,38 @@
|
||||||
|
{% load i18n %}
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
<button type="button" class="btn btn-success pull-right">
|
<a href="#AddUser" type="button" class="btn btn-success pull-right" data-toggle="modal">
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||||
</button>
|
</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">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title">{% trans "Add New User" %}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Name" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="text" class="form-control" name="name" placeholder="john" required pattern="[a-z0-9]+">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Password" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="password" class="form-control" name="password" placeholder="*******" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" 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 %}
|
{% endif %}
|
5
templates/create_user_inst_block.html
Normal file
5
templates/create_user_inst_block.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{% if request.user.is_superuser %}
|
||||||
|
<button type="button" class="btn btn-success pull-right">
|
||||||
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
|
@ -5,6 +5,7 @@
|
||||||
<!-- Page Heading -->
|
<!-- Page Heading -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
{% include 'create_user_inst_block.html' %}
|
||||||
<h1 class="page-header">{{ user }}</h1>
|
<h1 class="page-header">{{ user }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,6 +14,102 @@
|
||||||
{% include 'errors_block.html' %}
|
{% include 'errors_block.html' %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{ user }}
|
<div class="col-lg-12">
|
||||||
|
{% if not user_insts %}
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="alert alert-warning alert-dismissable">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
|
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "User doesn't have any Instace" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>{% trans "Name" %}</th>
|
||||||
|
<th>{% trans "Is blocked" %}</th>
|
||||||
|
<th>{% trans "Can change" %}</th>
|
||||||
|
<th>{% trans "Can delete" %}</th>
|
||||||
|
<th colspan="2">{% trans "Action" %}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for inst in user_insts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ forloop.counter }}</td>
|
||||||
|
<td>{{ inst.instance.name }}</td>
|
||||||
|
<td>{{ inst.is_block }}</td>
|
||||||
|
<td>{{ inst.is_change }}</td>
|
||||||
|
<td>{{ inst.is_delete }}</td>
|
||||||
|
<td style="width:5px;">
|
||||||
|
<a href="#editPriv{{ forloop.counter }}" type="button" class="btn btn-xs btn-default" data-toggle="modal">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Modal pool -->
|
||||||
|
<div class="modal fade" id="editPriv{{ forloop.counter }}" tabindex="-1" role="dialog" aria-labelledby="editPrivLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title">{% trans "Edit privilegies for" %} {{ inst.instance.name }}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Is blocked" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="hidden" name="user_inst" value="{{ inst.id }}">
|
||||||
|
<select type="text" class="form-control" name="inst_block">
|
||||||
|
<option value="">False</option>
|
||||||
|
<option value="1">True</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Can change" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<select type="text" class="form-control" name="inst_change">
|
||||||
|
<option value="">False</option>
|
||||||
|
<option value="1">True</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Can delete" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<select type="text" class="form-control" name="inst_delete">
|
||||||
|
<option value="">False</option>
|
||||||
|
<option value="1">True</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" 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 -->
|
||||||
|
</td>
|
||||||
|
<td style="width:5px;">
|
||||||
|
<form action="" method="post" role="form">{% csrf_token %}
|
||||||
|
<input type="hidden" name="user_inst" value="{{ inst.id }}">
|
||||||
|
<button type="submit" class="btn btn-xs btn-default" name="delete" tittle="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
|
||||||
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -13,22 +13,29 @@
|
||||||
|
|
||||||
{% include 'errors_block.html' %}
|
{% include 'errors_block.html' %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<div id="{{ user.username }}" class="col-xs-6 col-sm-4">
|
<div id="{{ user.username }}" class="col-xs-12 col-sm-4">
|
||||||
<div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data">
|
<div class="panel {% if user.is_active %}panel-success{% else %}panel-danger{% endif %} panel-data">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title"><strong>{{ user.username }}</strong>
|
<h3 class="panel-title">
|
||||||
<a data-toggle="modal" href="{% url 'user' user.id %}" class="pull-right"
|
<a href="{% url 'user' user.id %}"><strong>{{ user.username }}</strong></a>
|
||||||
title="{% trans "Edit" %}">
|
|
||||||
<span class="glyphicon glyphicon-cog"></span>
|
|
||||||
</a>
|
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>Status: {% if user.is_active %}Active{% else %}Blocked{% endif %}
|
<div class="col-xs-4 col-sm-4">
|
||||||
</p>
|
<p><strong>{% trans "Status:" %}</strong></p>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-4 col-sm-6">
|
||||||
|
{% if user.is_active %}
|
||||||
|
<p>{% trans "Active" %}</p>
|
||||||
|
{% else %}
|
||||||
|
<p>{% trans "Blocked" %}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
24
users/forms.py
Normal file
24
users/forms.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import re
|
||||||
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserAddForm(forms.Form):
|
||||||
|
name = forms.CharField(label="Name",
|
||||||
|
error_messages={'required': _('No User name has been entered')},
|
||||||
|
max_length=20)
|
||||||
|
password = forms.CharField(required=True, error_messages={'required': _('No password has been entered')},)
|
||||||
|
|
||||||
|
def clean_name(self):
|
||||||
|
name = self.cleaned_data['name']
|
||||||
|
have_symbol = re.match('^[a-z0-9]+$', name)
|
||||||
|
if not have_symbol:
|
||||||
|
raise forms.ValidationError(_('The flavor name must not contain any special characters'))
|
||||||
|
elif len(name) > 20:
|
||||||
|
raise forms.ValidationError(_('The flavor name must not exceed 20 characters'))
|
||||||
|
try:
|
||||||
|
User.objects.get(username=name)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return name
|
||||||
|
raise forms.ValidationError(_('Flavor name is already use'))
|
|
@ -2,6 +2,8 @@ from django.shortcuts import render
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from users.models import UserInstance
|
||||||
|
from users.forms import UserAddForm
|
||||||
|
|
||||||
|
|
||||||
def users(request):
|
def users(request):
|
||||||
|
@ -16,8 +18,22 @@ def users(request):
|
||||||
if not request.user.is_superuser:
|
if not request.user.is_superuser:
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
error_messages = []
|
||||||
users = User.objects.filter(is_staff=False, is_superuser=False)
|
users = User.objects.filter(is_staff=False, is_superuser=False)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
if 'create' in request.POST:
|
||||||
|
form = UserAddForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
data = form.cleaned_data
|
||||||
|
else:
|
||||||
|
for msg_err in form.errors.values():
|
||||||
|
error_messages.append(msg_err.as_text())
|
||||||
|
if not error_messages:
|
||||||
|
new_user = User.objects.create_user(data['name'], None, data['password'])
|
||||||
|
new_user.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
return render(request, 'users.html', locals())
|
return render(request, 'users.html', locals())
|
||||||
|
|
||||||
def user(request, user_id):
|
def user(request, user_id):
|
||||||
|
@ -33,5 +49,24 @@ def user(request, user_id):
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
user = User.objects.get(id=user_id)
|
user = User.objects.get(id=user_id)
|
||||||
|
user_insts = UserInstance.objects.filter(user_id=user_id)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
if 'delete' in request.POST:
|
||||||
|
user_inst = request.POST.get('user_inst', '')
|
||||||
|
del_user_inst = UserInstance.objects.get(id=user_inst)
|
||||||
|
del_user_inst.delete()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'edit' in request.POST:
|
||||||
|
user_inst = request.POST.get('user_inst', '')
|
||||||
|
inst_block = request.POST.get('inst_block', '')
|
||||||
|
inst_change = request.POST.get('inst_change', '')
|
||||||
|
inst_delete = request.POST.get('inst_delete', '')
|
||||||
|
edit_user_inst = UserInstance.objects.get(id=user_inst)
|
||||||
|
edit_user_inst.is_block = bool(inst_block)
|
||||||
|
edit_user_inst.is_change = bool(inst_change)
|
||||||
|
edit_user_inst.is_delete = bool(inst_delete)
|
||||||
|
edit_user_inst.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
return render(request, 'user.html', locals())
|
return render(request, 'user.html', locals())
|
Loading…
Reference in a new issue