From e489173e7ccbe7593e263b705c7937ff5be62b10 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Thu, 23 Feb 2023 13:04:50 +0100 Subject: add prototype for table of users --- server/templates/server/user_list_table.html | 98 ++++++++++++++++++++++++++++ server/urls.py | 1 + server/views.py | 21 ++++++ 3 files changed, 120 insertions(+) create mode 100644 server/templates/server/user_list_table.html (limited to 'server') diff --git a/server/templates/server/user_list_table.html b/server/templates/server/user_list_table.html new file mode 100644 index 0000000..ede8d9d --- /dev/null +++ b/server/templates/server/user_list_table.html @@ -0,0 +1,98 @@ +{% extends 'registration/base_admin.html' %} + +{% block title %}Admin - Lista Utenti{% endblock %} + +{% block breadcrumb %} + Admin + Lista Utenti +{% endblock %} +{% block toolbar %} + +{% endblock %} + +{% block content %} + + +
+{% endblock %} + +{% block script %} + $(document).ready(function(){ + $('#modal1').modal(); + }); + + var tabledata = [ + {% for user in users %} + { + username: "{{user.user.username}}", + name: "{{user.user.first_name}}", + last_name: "{{user.user.last_name}}", + email: "{{user.user.email}}", + }, + {% endfor %} + ]; + + var columns = []; + + var col_categories = [ + {field: "base", name: "Informazioni base", cols: + [ + {title: "Username", field: "username"}, + {title: "Nome", field: "name"}, + {title: "Cognome", field: "last_name"}, + {title: "Email", field: "email", visible: false}, + ] + }, + ] + + var col_select = document.getElementById("column-select"); + for (var j = 0; j < col_categories.length; j++) { + col_select.innerHTML += '
'; + var all_visible = true; + for (var i = 0; i < col_categories[j].cols.length; i++) { + columns.push(col_categories[j].cols[i]); + if (columns[i].visible == false) { + col_select.innerHTML += '
'; + all_visible = false; + } else { + col_select.innerHTML += '
'; + } + } + + var cat_elem = document.getElementById("category_"+col_categories[j].field); + + if (all_visible) { + cat_elem.checked = true; + } + } + + //initialize table + var table = new Tabulator("#example-table", { + responsiveLayout:true, + data:tabledata, + columns:columns, + }); + + function update_cols() { + for (var i = 0; i < columns.length; i++) { + if (document.getElementById("filter_"+columns[i].field).checked) { + table.showColumn(columns[i].field); + } else { + table.hideColumn(columns[i].field); + } + } + } +{% endblock %} \ No newline at end of file diff --git a/server/urls.py b/server/urls.py index d7974eb..b49a027 100644 --- a/server/urls.py +++ b/server/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path('', views.index, name='server'), path('uapprove', views.uapprove, name='uapprove'), path('ulist', views.ulist, name='ulist'), + path('ulist-table', views.ulist_table, name='ulist-table'), path('doctype', views.doctype, name='doctype'), path('doccreate', views.doccreate, name='doccreate'), path('docedit', views.docedit, name='docedit'), diff --git a/server/views.py b/server/views.py index 0ba3f63..66fa1c7 100644 --- a/server/views.py +++ b/server/views.py @@ -458,6 +458,27 @@ def ulist(request): } return render(request, 'server/user_list.html', context) +@staff_member_required +def ulist_table(request): + context = {} + # group name and obj + group = getGroups(request)[0] + + # list users with their documents + permission = Permission.objects.get(codename="approved") + + usercodes = UserCode.objects.filter(Q(user__user_permissions=permission) | Q(user__is_staff=True)).filter(user__groups__name__contains=group.name).select_related("user", "medic").order_by("user__last_name") + + vac_file = ["/server/media/", "/vac_certificate/usercode"] + health_file = ["/server/media/", "/health_care_certificate/usercode"] + + context = { + 'users': usercodes, + 'vac_file': vac_file, + 'health_file': health_file, + } + return render(request, 'server/user_list_table.html', context) + @user_passes_test(isStaff) def doctype(request): -- cgit v1.2.1