Implement bootstrap multiple deletion view, Implement table, Cloase #26

This commit is contained in:
Götz 2019-04-10 19:47:08 +02:00
parent 8365ba777e
commit 9f88025076
6 changed files with 161 additions and 28 deletions

View File

@ -81,7 +81,7 @@ def realm_user_delete(request, realm_id, user_dn):
LdapUser.base_dn = f'ou=people,{realm_obj.ldap_base_dn}'
LdapGroup.base_dn = f'ou=groups,{realm_obj.ldap_base_dn}'
ldap_user = LdapUser.objects.get(dn=user_dn)
user_delete_controller(ldap_user)
user_delete_controller(ldap_user, realm_obj)
return redirect('realm-user-list', realm_id)
@ -93,11 +93,13 @@ def realm_multiple_user_delete(request, realm_id):
ldap_users = form.cleaned_data['ldap_users']
for ldap_user in ldap_users:
# TODO: Failure catchup
user_delete_controller(ldap_user)
user_delete_controller(ldap_user, realm)
return redirect('realm-user-list', realm_id)
# TODO: Form not valid
form = UserDeleteListForm()
return render(request, 'realm/realm_user_multiple_delete.jinja2', {'form': form, 'realm': realm})
LdapUser.base_dn = realm.ldap_base_dn
users = LdapUser.objects.all()
return render(request, 'realm/realm_user_multiple_delete.jinja2', {'form': form, 'realm': realm, 'users': users})
@login_required
@ -131,7 +133,7 @@ def user_delete(request, realm_id, user_dn):
LdapGroup.base_dn = f'ou=groups,{realm_obj.ldap_base_dn}'
ldap_user = LdapUser.objects.get(dn=user_dn)
if request.user.username == ldap_user.username:
user_delete_controller(ldap_user)
user_delete_controller(ldap_user, realm_obj)
return redirect('account-deleted', realm_id)
else:
return redirect('permission-denied')
@ -162,10 +164,13 @@ def user_update_controller(ldap_user, realm_id, realm_obj, request, user_dn, red
return render(request, detail_page, {'form': form, 'realm': realm_obj, 'user': ldap_user})
def user_delete_controller(ldap_user):
def user_delete_controller(ldap_user, realm):
LdapGroup.base_dn = f'ou=groups,{realm.ldap_base_dn}'
user_groups = LdapGroup.objects.filter(members__contains=ldap_user.dn)
print(user_groups)
for group in user_groups:
print(group)
# LdapGroup.base_dn = group.base_dn
group.members.remove(ldap_user.dn)
group.save()
ldap_user.delete()

View File

@ -110,4 +110,63 @@
.wrapper.toggled .sidebar-wrapper {
margin-left: -15rem;
}
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* -- Data Tables -- */
/* ------------------------------------------------------------------------------------------------------------------ */
/*!* Hide stuff from dataTables that we do not neeed *!*/
/*.dataTables_length, .dataTables_info, .dataTables_paginate {*/
/*!*visibility: hidden*!*/
/*}*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* -- Multiple User deletion Custom checkbox -- */
/* ------------------------------------------------------------------------------------------------------------------ */
.table-checkbox-control-label::before {
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.table-checkbox-control-label::before {
/* position: absolute; */
top: 0.25rem;
left: -1.5rem;
display: block;
width: 1.2rem;
height: 1.2rem;
pointer-events: none;
content: "";
background-color: #fff;
border: #adb5bd solid 1px;
}
.table-checkbox-control-input:checked ~ .table-checkbox-control-label::before {
color: #fff;
border-color: var(--danger);
background-color: var(--danger);
}
.table-checkbox-control-label::after {
position: absolute;
top: 0.25rem;
left: -1.5rem;
display: block;
/*width: 1.5rem;*/
/*height: 1.5rem;*/
content: "";
background: no-repeat 50% / 50% 50%;
}
.table-checkbox-control-label {
position: relative;
margin-bottom: 0;
vertical-align: middle;
}
.table-checkbox-control-input {
position: absolute;
z-index: -1;
opacity: 0;
}

22
static/js/main.js Normal file
View File

@ -0,0 +1,22 @@
// make the table a dataTable and show all entries by default
const TABLE_CLASS = '.data-table';
$(document).ready(function () {
// if ($(TABLE_CLASS)) {
const data_table = $(TABLE_CLASS).DataTable({
"lengthMenu": [[-1], ["All"]],
"dom": 'it'
});
// }
$('#data-table-search-input').keyup(function () {
data_table.search($(this).val()).draw();
});
$("#delete-all-checkbox").change(function () {
if (document.getElementById('delete-all-checkbox').checked) {
$('.delete-checkbox').prop("checked", true);
} else {
$('.delete-checkbox').prop("checked", false);
}
});
});

View File

@ -14,16 +14,11 @@
<meta name="author" content="Michael Götz"/>
{% block js_extra %}{% endblock %}
<!-- Bootstrap CSS -->
{# <link rel="stylesheet" href="{{ static('libs/font-awesome-4.7.0/css/font-awesome.css') }}">#}
<link rel="stylesheet" href="{{ static('libs/bootstrap-4.3.1-dist/css/bootstrap.css') }}">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link rel="stylesheet" href="{{ static('css/floating_labels.css') }}">
{# <link rel="stylesheet" href="{{ static('home/main.css') }}">#}
{# <script src="{{ static('libs/jquery-3.3.1.min.js') }}"></script>#}
{# <script src="{{ static('libs/handlebars-379172e.js') }}"></script>#}
{# <script src="{{ static('js/main.js') }}"></script>#}
{# <script src="{{ static('libs/popper.js-1.14.4/dist/umd/popper.js') }}"></script>#}
{# <script src="{{ static('libs/bootstrap-4.0.0-beta-dist/js/bootstrap.js') }}"></script>#}
{# <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.12/handlebars.js"></script>#}
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">
{% block css_extra %}{% endblock %}
@ -49,14 +44,13 @@
</nav>
{% block body %}
{# <div class="container-fluid">#}
{# <div class="row">{% block bottom_nav %}{% endblock %}</div>#}
{# <div class="row">#}
{% block content %}{% endblock %}
{# </div>#}
{# </div>#}
{% endblock %}
<script src="{{ static('js/form.js') }}"></script>
{% block js_tail %}{% endblock %}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="{{ static('js/main.js') }}"></script>
</body>
</html>

View File

@ -1,24 +1,36 @@
{% extends 'realm/realm_detailed.jinja2' %}
{% block detail_content %}
<h2>Nutzer</h2>
<a href="{{ url('realm-multiple-user-delete', args=[realm.id]) }}" class="text-right"> Mehrere Nutzer Löschen</a>
<table class="table">
<div class="form-group w-25 float-right">
<input type="text"
class="form-control"
id="data-table-search-input">
<label for="data-table-search-input">Suche</label>
</div>
<table class="table table-hover table-striped table-inverse table-bordered data-table">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Ldap Domain</th>
<th scope="col">Nutzername</th>
<th scope="col">E-Mail</th>
<th scope="col">Vorname</th>
<th scope="col">Nachname</th>
</tr>
</thead>
<tbody>
{% for user in realm_user %}
<tr>
<td>{{ user.username }}</td>
<td>
<a href="{{ url('realm-user-detail', args=[realm.id, user.dn]) }}">{{ user.dn }}</a>
</td>
<td>{{ user.email }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
{# <td>#}
{# <a href="{{ url('realm-user-detail', args=[realm.id, user.dn]) }}">{{ user.dn }}</a>#}
{# </td>#}
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ url('realm-user-add', args=[realm.id]) }}" class="btn btn-primary">Nutzer hinzufügen</a>
<a href="{{ url('realm-multiple-user-delete', args=[realm.id]) }}" class="btn btn-danger"> Mehrere Nutzer
Löschen</a>
{% endblock %}

View File

@ -3,9 +3,50 @@
{% block detail_content %}
<h2>Nutzer löschen</h2>
<div class="form-group w-25 float-right">
<input type="text"
class="form-control"
placeholder="Personen Suche"
id="data-table-search-input">
<label for="data-table-search-input">Suche</label>
</div>
<form action="{{ url('realm-multiple-user-delete', args=[realm.id]) }}" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
{{ form.as_p() }}
{# {{ form.as_p() }}#}
<table class="table table-hover table-striped table-inverse table-bordered data-table">
<thead>
<tr>
<th scope="col" class="text-center">
<input type="checkbox"
class="table-checkbox-control-input"
id="delete-all-checkbox"
><label class="table-checkbox-control-label" for="delete-all-checkbox"></label>
</th>
<th scope="col">Nutzername</th>
<th scope="col">E-Mail</th>
<th scope="col">Vorname</th>
<th scope="col">Nachname</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td class="text-center">
<input type="checkbox"
class="table-checkbox-control-input delete-checkbox"
id="user_{{ loop.index }}"
value="{{ user.username }}"
name="ldap_users"
><label class="table-checkbox-control-label" for="user_{{ loop.index }}"></label>
</td>
<td>{{ user.username }}</td>
<td>{{ user.email }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="d-flex mt-4">
<button type="submit" class="btn btn-danger mr-auto p-2">Ausführen</button>
<a href="{{ url('realm-user-list', args = [realm.id]) }}"