aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <aleporia@gmail.com>2023-07-27 11:26:43 +0200
committerAndrea Lepori <aleporia@gmail.com>2023-07-27 11:26:44 +0200
commit7577628b360c78742d4d9d1b709f3749ca4fa022 (patch)
treeb994b3f6044f225cae5a750928032458d5c2971a
parentcreate docs from uc (diff)
downloadscout-subs-7577628b360c78742d4d9d1b709f3749ca4fa022.tar.gz
scout-subs-7577628b360c78742d4d9d1b709f3749ca4fa022.zip
user list and branca tansfer with new uc
-rw-r--r--server/templates/server/index.html4
-rw-r--r--server/templates/server/user_list.html34
-rw-r--r--server/templates/server/user_list_table.html16
-rw-r--r--server/views.py63
-rw-r--r--version.txt2
5 files changed, 30 insertions, 89 deletions
diff --git a/server/templates/server/index.html b/server/templates/server/index.html
index 2db42e4..487ef71 100644
--- a/server/templates/server/index.html
+++ b/server/templates/server/index.html
@@ -48,7 +48,7 @@
<div class="hide-on-med-and-down">
<a class="waves-effect waves-light btn {{color}}" href="{% url 'ulist' %}">Utenti</a>
<a class="waves-effect waves-light btn {{color}}" href="{% url 'ulist-table' %}">Utenti (Tabella BETA)</a>
- <a class="waves-effect waves-light btn {{color}}" href="{% url 'uapprove' %}">Approva utente</a>
+ <a class="waves-effect waves-light btn {{color}}" href="{% url 'uapprove' %}">Trasferta utente</a>
<a class="waves-effect waves-light btn {{color}}" href="{% url 'request' %}">Richiedi dati</a>
</div>
@@ -56,7 +56,7 @@
<a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'ulist' %}">Utenti</a>
<br>
<br>
- <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'uapprove' %}">Approva utente</a>
+ <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'uapprove' %}">Trasferta utente</a>
<br>
<br>
<a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'request' %}">Richiedi dati</a>
diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html
index dffb8b2..22788e9 100644
--- a/server/templates/server/user_list.html
+++ b/server/templates/server/user_list.html
@@ -31,35 +31,9 @@
{% elif "capi" in user.user|user_groups %}
<i class="material-icons">star_border</i>
{% endif %}
- {{user.user.first_name}} {{user.user.last_name}}
+ {{user.first_name}} {{user.last_name}}
</div>
<div class="collapsible-body"><span>
- {% if not user.user.is_staff %}
- <div id="modal{{user.user.id}}" class="modal">
- <div class="modal-content">
- <h4>Attenzione</h4>
- <p>
- Sei sicuro di volerlere deapprovare l'utente {{user.user.first_name}} {{user.user.last_name}}?<br>
- Una volta deapprovato l'utente non potrà più creare documenti e per essere riapprovato dovrà essere usato il codice di approvazione.
- </p>
- </div>
- <div class="modal-footer">
- <a style="color:red" href="#!" class="modal-close waves-effect waves-green btn-flat">Annulla</a>
- <a onclick="send('d{{user.user.id}}')" class="modal-close waves-effect waves-green btn-flat">Deapprova</a>
- </div>
- </div>
- <div class="hide-on-med-and-down">
- <a class="waves-effect waves-light btn {{color}} modal-trigger" href="#modal{{user.user.id}}"><i class="material-icons left">remove_circle_outline</i>Deapprova utente</a>
- <a class="waves-effect waves-light btn {{color}}" onclick="send('c{{user.user.id}}')"><i class="material-icons left">star_border</i>Capo/non</a>
- </div>
- <div style="margin-bottom: 0px;" class="hide-on-large-only row">
- <a class="col s12 waves-effect waves-light btn {{color}} modal-trigger" href="#modal{{user.user.id}}"><i class="material-icons left">remove_circle_outline</i>Deapprova utente</a>
- <br>
- <br>
- <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('c{{user.user.id}}')"><i class="material-icons left">star_border</i>Capo/non</a>
- </div>
- <br><br>
- {% endif %}
<ul class="collection">
<li class="collection-item">
<i class="material-icons left">confirmation_number</i>U{{user.code}}
@@ -73,11 +47,11 @@
<div class="collapsible-body"><span>
<div class="row">
<div class="input-field col l4 s12">
- <input disabled value="{{user.user.first_name}}" id="first_name" type="text" >
+ <input disabled value="{{user.first_name}}" id="first_name" type="text" >
<label for="first_name">Nome</label>
</div>
<div class="input-field col l4 s12">
- <input disabled value="{{user.user.last_name}}" id="last_name" type="text" >
+ <input disabled value="{{user.last_name}}" id="last_name" type="text" >
<label for="last_name">Cognome</label>
</div>
<div class="input-field col l4 s12">
@@ -85,7 +59,7 @@
<label for="birth_date">Data di nascita</label>
</div>
<div class="input-field col l4 s12">
- <input disabled value="{{ user.user|user_primary_group }}" id="branca" type="text">
+ <input disabled value="{{ user.branca.name }}" id="branca" type="text">
<label for="branca">Branca</label>
</div>
<div class="input-field col l4 s12">
diff --git a/server/templates/server/user_list_table.html b/server/templates/server/user_list_table.html
index 89903a5..624fced 100644
--- a/server/templates/server/user_list_table.html
+++ b/server/templates/server/user_list_table.html
@@ -39,12 +39,12 @@
{% for user in users %}
{
capo: {% if "capi" in user.user|user_groups %}true{% else %}false{% endif %},
- username: "{{user.user.username}}",
- name: "{{user.user.first_name}}",
- last_name: "{{user.user.last_name}}",
+ ucode: "U{{user.code}}",
email: "{{user.user.email}}",
+ name: "{{user.first_name}}",
+ last_name: "{{user.last_name}}",
birth_date: "{{user.born_date}}",
- branca: "{{ user.user|user_primary_group }}",
+ branca: "{{ user.branca }}",
parent_name: "{{user.parent_name}}",
avs_number: "{{user.avs_number}}",
via: "{{user.via}}",
@@ -82,11 +82,11 @@
var col_categories = [
{field: "base", name: "Informazioni base", cols:
[
- {title: "Capo", field: "capo", formatter:"tickCross", frozen: true},
- {title: "Username", field: "username", frozen: true},
- {title: "Nome", field: "name"},
- {title: "Cognome", field: "last_name"},
+ {title: "Nome", field: "name", frozen: true},
+ {title: "Cognome", field: "last_name", frozen: true},
+ {title: "Capo", field: "capo", formatter:"tickCross"},
{title: "Email", field: "email"},
+ {title: "Codice", field: "ucode"},
{title: "Data di nascita", field: "birth_date"},
{title: "Branca", field: "branca"},
]
diff --git a/server/views.py b/server/views.py
index 4bcdf53..edb9d0c 100644
--- a/server/views.py
+++ b/server/views.py
@@ -144,10 +144,6 @@ def uapprove(request):
if request.method == "POST":
# get group name and obj
group = getGroups(request)[0]
- parent_group = group.name
-
- # get permission object
- permission = Permission.objects.get(codename='approved')
# parse text to array
data = request.POST["codes"]
@@ -163,21 +159,18 @@ def uapprove(request):
elif UserCode.objects.filter(code=data[i][1:]).count() == 0:
data[i] = data[i] + " - Invalido"
else:
- user = UserCode.objects.filter(code=data[i][1:])[0].user
- user.user_permissions.add(permission)
+ usercode = UserCode.objects.filter(code=data[i][1:])[0]
# if user not in any group add to the same group as staff
- if user.groups.values_list('name', flat=True).count() == 0:
- user.groups.add(group)
+ if usercode.branca == None:
+ usercode.branca = group
+ usercode.save()
data[i] = data[i] + " - Ok"
+ elif usercode.branca == group:
+ data[i] = data[i] + " - Già " + group.name
else:
- if user.groups.values_list('name', flat=True)[0] == parent_group:
- # if user already in group do nothing
- data[i] = data[i] + " - Già approvato"
- else:
- # if user in another group notify staff of group change
- user.groups.remove(Group.objects.get(name=user.groups.values_list('name', flat=True)[0]))
- user.groups.add(group)
- data[i] = data[i] + " - Ok, cambio branca"
+ usercode.branca = group
+ usercode.save()
+ data[i] = data[i] + " - Ok, cambio branca"
context = {
'messages': data,
@@ -379,14 +372,14 @@ def approve_direct(request):
def ulist(request):
context = {}
# group name and obj
- group = getGroups(request)[0]
+ groups = getGroups(request)
if request.method == "POST":
# request to download document
if request.POST["action"][0] == 'f':
document = Document.objects.get(id=request.POST["action"][1:])
# check if user has permission to view document
- if document.group == group:
+ if document.group == groups[0]:
vac_file = ""
health_file = ""
sign_doc_file = ""
@@ -419,34 +412,10 @@ def ulist(request):
pdf = pdfkit.from_string(html, False)
result = BytesIO(pdf)
result.seek(0)
- return FileResponse(result, filename=document.user.username+"_"+document.document_type.name+".pdf")
-
- # deapprove user
- elif request.POST["action"][0] == 'd':
- user = User.objects.get(id=request.POST["action"][1:])
- # check if user has permission to deapprove user
- if user.groups.all()[0] == group:
- permission = Permission.objects.get(codename="approved")
- user.user_permissions.remove(permission)
- return HttpResponseRedirect("ulist")
- # make user "capo"
- elif request.POST["action"][0] == 'c':
- user = User.objects.get(id=request.POST["action"][1:])
- capi = Group.objects.get(name="capi")
- # check if user has permission to modify
- if user.groups.all()[0] == group:
- if "capi" in user.groups.values_list('name', flat=True):
- # remove group
- user.groups.remove(capi)
- else:
- # add group
- user.groups.add(capi)
- return HttpResponseRedirect("ulist")
+ return FileResponse(result, filename=document.usercode.first_name+"_"+document.usercode.last_name+"_"+document.document_type.name+".pdf")
# 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")
+ usercodes = UserCode.objects.filter(branca__in=groups).select_related("user", "medic").order_by("last_name")
vac_file = ["/server/media/", "/vac_certificate/usercode"]
health_file = ["/server/media/", "/health_care_certificate/usercode"]
@@ -462,12 +431,10 @@ def ulist(request):
def ulist_table(request):
context = {}
# group name and obj
- group = getGroups(request)[0]
+ groups = getGroups(request)
# 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")
+ usercodes = UserCode.objects.filter(branca__in=groups).select_related("user", "medic").order_by("user__last_name")
vac_file = ["/server/media/", "/vac_certificate/usercode"]
health_file = ["/server/media/", "/health_care_certificate/usercode"]
diff --git a/version.txt b/version.txt
index c157b42..b110dc6 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
version=0.6
-rev=32
+rev=33