mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
Added users management
This commit is contained in:
parent
2e976fc101
commit
bf5b0a9a42
2 changed files with 80 additions and 0 deletions
|
@ -20,6 +20,9 @@
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h3 class="panel-title">
|
<h3 class="panel-title">
|
||||||
<a href="{% url 'user' user.id %}"><strong>{{ user.username }}</strong></a>
|
<a href="{% url 'user' user.id %}"><strong>{{ user.username }}</strong></a>
|
||||||
|
<a data-toggle="modal" href="#editUser{{ user.id }}" class="pull-right" title="{% trans "Edit" %}">
|
||||||
|
<span class="glyphicon glyphicon-cog"></span>
|
||||||
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
@ -36,6 +39,55 @@
|
||||||
</div>
|
</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">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title">{% trans "Edit user info" %}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-horizontal" method="post" 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="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">
|
||||||
|
<label class="col-sm-4 control-label">{% trans "Password" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="password" name="user_pass" class="form-control" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="pull-left btn btn-danger" name="delete">
|
||||||
|
{% trans "Delete" %}
|
||||||
|
</button>
|
||||||
|
{% if user.is_active %}
|
||||||
|
<button type="submit" class="pull-left btn btn-warning" name="block">
|
||||||
|
{% trans "Block" %}
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button type="submit" class="pull-left btn btn-success" name="unblock">
|
||||||
|
{% trans "Unblock" %}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
<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>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -35,6 +35,34 @@ def users(request):
|
||||||
new_user = User.objects.create_user(data['name'], None, data['password'])
|
new_user = User.objects.create_user(data['name'], None, data['password'])
|
||||||
new_user.save()
|
new_user.save()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'edit' in request.POST:
|
||||||
|
user_id = request.POST.get('user_id', '')
|
||||||
|
user_pass = request.POST.get('user_pass', '')
|
||||||
|
user_edit = User.objects.get(id=user_id)
|
||||||
|
user.password = user_pass
|
||||||
|
user_edit.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'block' in request.POST:
|
||||||
|
user_id = request.POST.get('user_id', '')
|
||||||
|
user_block = User.objects.get(id=user_id)
|
||||||
|
user_block.is_active = False
|
||||||
|
user_block.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'unblock' in request.POST:
|
||||||
|
user_id = request.POST.get('user_id', '')
|
||||||
|
user_unblock = User.objects.get(id=user_id)
|
||||||
|
user_unblock.is_active = True
|
||||||
|
user_unblock.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'delete' in request.POST:
|
||||||
|
user_id = request.POST.get('user_id', '')
|
||||||
|
try:
|
||||||
|
del_user_inst = UserInstance.objects.filter(user_id=user_id)
|
||||||
|
del_user_inst.delete()
|
||||||
|
finally:
|
||||||
|
user_delete = User.objects.get(id=user_id)
|
||||||
|
user_delete.delete()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
return render(request, 'users.html', locals())
|
return render(request, 'users.html', locals())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue