diff options
-rw-r--r-- | client/templatetags/app_filter.py | 19 | ||||
-rw-r--r-- | server/templates/server/data_request.html | 10 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 2 | ||||
-rw-r--r-- | server/templates/server/user_list.html | 101 | ||||
-rw-r--r-- | server/views.py | 194 | ||||
-rw-r--r-- | version.txt | 2 |
6 files changed, 152 insertions, 176 deletions
diff --git a/client/templatetags/app_filter.py b/client/templatetags/app_filter.py index 3120b8e..e49e8a9 100644 --- a/client/templatetags/app_filter.py +++ b/client/templatetags/app_filter.py @@ -1,7 +1,22 @@ from django import template -from client.models import KeyVal +from django.db.models.query_utils import Q +from client.models import Document, KeyVal register = template.Library() @register.filter(name="doc_key") def doc_key(doc): - return KeyVal.objects.filter(container=doc)
\ No newline at end of file + return KeyVal.objects.filter(container=doc) + +@register.filter(name="user_docs") +def user_docs(admin_user, user): + parent_group = admin_user.groups.values_list('name', flat=True)[0] + documents = Document.objects.filter(Q(user=user) & ~Q(status='archive') & Q(group__name=parent_group)) + return documents + +@register.filter(name="user_groups") +def user_groups(user): + return user.groups.values_list('name', flat=True) + +@register.filter(name="user_primary_group") +def user_primary_group(user): + return user.groups.values_list('name', flat=True)[0]
\ No newline at end of file diff --git a/server/templates/server/data_request.html b/server/templates/server/data_request.html index fbbcbc0..7728cd9 100644 --- a/server/templates/server/data_request.html +++ b/server/templates/server/data_request.html @@ -29,7 +29,7 @@ </div> <div class="card-action"> <a class="waves-effect waves-light btn {{color}}" href="#" onclick="document.getElementById('form').submit()">Invia</a> - <a class="waves-effect waves-light btn {{color}}" onclick="copy()">Copia risultato</a> + <a class="waves-effect waves-light btn {{color}}" onclick="copy()" id="copy_btn">Copia risultato</a> </div> </form> </div> @@ -38,6 +38,12 @@ {% endblock %} {% block script %} +$(document).ready(function(){ + {% if error %} + M.toast({html: '{{ error }}', classes: 'orange'}) + {% endif %} +}); + document.addEventListener('DOMContentLoaded', function() { var elems = document.querySelectorAll('select'); var options = {}; @@ -45,6 +51,8 @@ document.addEventListener('DOMContentLoaded', function() { }); function copy() { + M.toast({html: 'Valore copiato!', classes: 'green'}) + var copyText = document.getElementById("data"); copyText.select(); copyText.setSelectionRange(0, 99999); /*For mobile devices*/ diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index 1ef1433..047a15a 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -146,7 +146,7 @@ <div class="collapsible-body"><span> <div class="hide-on-med-and-down"> <a class="waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a> - <a class="waves-effect waves-light btn {{color}}" onclick="send('d{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a> + <a class="waves-effect waves-light btn {{color}}" onclick="send('p{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a> {% if doctype.0.medical_data %} <a class="waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a> {% endif %} diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html index aa2f43e..a14daea 100644 --- a/server/templates/server/user_list.html +++ b/server/templates/server/user_list.html @@ -18,6 +18,7 @@ {% endblock %} {% block content %} +{% load app_filter %} <form id="form" action="{% url 'ulist' %}" method="post"> {% csrf_token %} <input type="hidden" name="action" id="action"> @@ -25,43 +26,43 @@ {% for user in users %} <li> <div class="collapsible-header list"> - {% if user.0.is_staff %} + {% if user.user.is_staff %} <i class="material-icons">star</i> - {% elif user.6 %} + {% elif "capi" in user.user|user_groups %} <i class="material-icons">star_border</i> {% endif %} - {{user.0.first_name}} {{user.0.last_name}} + {{user.user.first_name}} {{user.user.last_name}} </div> <div class="collapsible-body"><span> - {% if not user.0.is_staff %} - <div id="modal{{user.0.id}}" class="modal"> + {% 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.0.first_name}} {{user.0.last_name}}?<br> + 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.0.id}}')" class="modal-close waves-effect waves-green btn-flat">Deapprova</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.0.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.0.id}}')"><i class="material-icons left">star_border</i>Capo/non</a> + <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.0.id}}"><i class="material-icons left">remove_circle_outline</i>Deapprova utente</a> + <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.0.id}}')"><i class="material-icons left">star_border</i>Capo/non</a> + <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.1.code}} + <i class="material-icons left">confirmation_number</i>U{{user.code}} </li> </ul> <ul class="collapsible"> @@ -72,63 +73,63 @@ <div class="collapsible-body"><span> <div class="row"> <div class="input-field col l4 s12"> - <input disabled value="{{user.0.first_name}}" id="first_name" type="text" > + <input disabled value="{{user.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.0.last_name}}" id="last_name" type="text" > + <input disabled value="{{user.user.last_name}}" id="last_name" type="text" > <label for="last_name">Cognome</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.born_date}}" id="birth_date" type="text"> + <input disabled value="{{user.born_date}}" id="birth_date" type="text"> <label for="birth_date">Data di nascita</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.2}}" id="branca" type="text"> + <input disabled value="{{ user.user|user_primary_group }}" id="branca" type="text"> <label for="branca">Branca</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.parent_name}}" id="parent_name" type="text" > + <input disabled value="{{user.parent_name}}" id="parent_name" type="text" > <label for="parent_name">Nome dei genitori</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.avs_number}}" id="avs_number" type="text"> + <input disabled value="{{user.avs_number}}" id="avs_number" type="text"> <label for="avs_number">Numero AVS</label> </div> <div class="input-field col l12 s12"> - <input value="{{user.1.via}}" disabled id="via" type="text" > + <input value="{{user.via}}" disabled id="via" type="text" > <label for="via">Via e numero</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.cap}}" name="cap" id="cap" type="text" > + <input disabled value="{{user.cap}}" name="cap" id="cap" type="text" > <label for="cap">CAP</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.country}}" name="country" id="country" type="text" > + <input disabled value="{{user.country}}" name="country" id="country" type="text" > <label for="country">Paese</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.nationality}}" name="nationality" id="nationality" type="text" > + <input disabled value="{{user.nationality}}" name="nationality" id="nationality" type="text" > <label for="nationality">Nazionalità</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.phone}}" name="phone" id="phone" type="text" > + <input disabled value="{{user.phone}}" name="phone" id="phone" type="text" > <label for="phone">Cellulare</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.home_phone}}" name="home_phone" id="home_phone" type="text" > + <input disabled value="{{user.home_phone}}" name="home_phone" id="home_phone" type="text" > <label for="home_phone">Telefono di casa</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.0.email}}" name="email" id="email" type="text" > + <input disabled value="{{user.user.email}}" name="email" id="email" type="text" > <label for="email">Email</label> </div> <div class="input-field col l8 s12"> - <input disabled value="{{user.1.school}}" name="school" id="school" type="text" > + <input disabled value="{{user.school}}" name="school" id="school" type="text" > <label for="school">Scuola frequentata</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.year}}" name="year" id="year" type="text" > + <input disabled value="{{user.year}}" name="year" id="year" type="text" > <label for="year">Classe</label> </div> </div> @@ -146,23 +147,23 @@ </div> <div class="row"> <div class="input-field col l6 s12"> - <input disabled name="emer_name" value="{{user.1.medic.emer_name}}" id="emer_name" type="text" > + <input disabled name="emer_name" value="{{user.medic.emer_name}}" id="emer_name" type="text" > <label for="emer_name">Nome e cognome</label> </div> <div class="input-field col l3 s12"> - <input disabled name="emer_relative" value="{{user.1.medic.emer_relative}}" id="emer_relative" type="text" > + <input disabled name="emer_relative" value="{{user.medic.emer_relative}}" id="emer_relative" type="text" > <label for="emer_releative">Parentela</label> </div> <div class="input-field col l3 s12"> - <input disabled name="cell_phone" value="{{user.1.medic.cell_phone}}" id="cellphone" type="text" > + <input disabled name="cell_phone" value="{{user.medic.cell_phone}}" id="cellphone" type="text" > <label for="cell_phone">Cellulare</label> </div> <div class="input-field col l9 s12"> - <input disabled value="{{user.1.medic.address}}" name="address" id="address" type="text" > + <input disabled value="{{user.medic.address}}" name="address" id="address" type="text" > <label for="address">Indirizzo completo</label> </div> <div class="input-field col l3 s12"> - <input disabled value="{{user.1.medic.emer_phone}}" name="emer_phone" id="emer_phone" type="text" > + <input disabled value="{{user.medic.emer_phone}}" name="emer_phone" id="emer_phone" type="text" > <label for="emer_phone">Telefono di casa</label> </div> </div> @@ -173,15 +174,15 @@ </div> <div class="row"> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.medic.health_care}}" name="health_care" id="health_care" type="text" > + <input disabled value="{{user.medic.health_care}}" name="health_care" id="health_care" type="text" > <label for="health_care">Cassa Malati</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.medic.injuries}}" name="injuries" id="injuries" type="text" > + <input disabled value="{{user.medic.injuries}}" name="injuries" id="injuries" type="text" > <label for="injuries">Infortuni</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{user.1.medic.rc}}" name="rc" id="rc" type="text" > + <input disabled value="{{user.medic.rc}}" name="rc" id="rc" type="text" > <label for="rc">Responsabilità civile</label> </div> </div> @@ -190,7 +191,7 @@ È sostenitore REGA <label> No - <input disabled name="rega" type="checkbox" {% if user.1.medic.rega %}checked="checked"{%endif%}> + <input disabled name="rega" type="checkbox" {% if user.medic.rega %}checked="checked"{%endif%}> <span class="lever"></span> Si </label> @@ -201,15 +202,15 @@ <h6>Medico di famiglia</h6> </div> <div class="input-field col l6 s12"> - <input disabled value="{{user.1.medic.medic_name}}" name="medic_name" id="medic_name" type="text" > + <input disabled value="{{user.medic.medic_name}}" name="medic_name" id="medic_name" type="text" > <label for="medic_name">Nome e cognome</label> </div> <div class="input-field col l6 s12"> - <input disabled value="{{user.1.medic.medic_phone}}" name="medic_phone" id="medic_phone" type="text" > + <input disabled value="{{user.medic.medic_phone}}" name="medic_phone" id="medic_phone" type="text" > <label for="medic_phone">Telefono studio</label> </div> <div class="input-field col l12 s12"> - <input disabled value="{{user.1.medic.medic_address}}" name="medic_address" id="medic_address" type="text" > + <input disabled value="{{user.medic.medic_address}}" name="medic_address" id="medic_address" type="text" > <label for="medic_address">Indirizzo completo</label> </div> </div> @@ -218,45 +219,45 @@ <h6>Scheda medica personale</h6> </div> <div class="input-field col s12"> - <input disabled value="{{user.1.medic.sickness}}" name="sickness" id="sickness" type="text"> + <input disabled value="{{user.medic.sickness}}" name="sickness" id="sickness" type="text"> <label for="sickness">Principali malattie avute</label> </div> <div class="input-field col l8 s12"> - <input disabled value="{{user.1.medic.vaccine}}" name="vaccine" id="vaccine" type="text"> + <input disabled value="{{user.medic.vaccine}}" name="vaccine" id="vaccine" type="text"> <label for="vaccine">Vacinazioni fatte</label> </div> <div class="input-field col l4 s12"> <label for="tetanus_date">Ultima vacinazione contro il tetano</label> - <input disabled value="{{user.1.medic.tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text"> + <input disabled value="{{user.medic.tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text"> </div> <div class="input-field col s12"> - <input disabled value="{{user.1.medic.allergy}}" name="allergy" id="allergy" type="text"> + <input disabled value="{{user.medic.allergy}}" name="allergy" id="allergy" type="text"> <label for="allergy">Allergie particolari/Intolleraze alimentari</label> </div> <div class="switch col s12"> Deve assumere regolarmente medicamenti <label> No - <input disabled name="drugs_bool" type="checkbox" {% if user.1.medic.drugs_bool %}checked="checked"{%endif%}> + <input disabled name="drugs_bool" type="checkbox" {% if user.medic.drugs_bool %}checked="checked"{%endif%}> <span class="lever"></span> Si </label> </div> <div class="input-field col s12"> - <input disabled value="{{user.1.medic.drugs}}" name="drugs" id="drugs" type="text"> + <input disabled value="{{user.medic.drugs}}" name="drugs" id="drugs" type="text"> <label for="drugs">Se sì quali, in che dosi e prescrizioni</label> </div> <div class="switch col s12"> Informazioni particolari sullo stato di salute: (postumi di operazioni, incidenti, malattie, disturbi fisici) <label> No - <input disabled name="misc_bool" type="checkbox" {% if user.1.medic.misc_bool %}checked="checked"{%endif%}> + <input disabled name="misc_bool" type="checkbox" {% if user.medic.misc_bool %}checked="checked"{%endif%}> <span class="lever"></span> Si </label> </div> <div class="input-field col s12"> - <input disabled value="{{user.1.medic.misc}}" name="misc" id="misc" type="text"> + <input disabled value="{{user.medic.misc}}" name="misc" id="misc" type="text"> <label for="misc">Se sì quali</label> </div> </span></div> @@ -270,7 +271,7 @@ <div class="col s12"> <div class="card"> <div class="card-image"> - {% if user.4 %}<img class="lazyload" data-src="{{ user.4 }}">{% endif %} + {% if user.medic.health_care_certificate %}<img class="lazyload" data-src="{{ health_file.0 }}{{ user.id }}{{ health_file.1}}">{% endif %} </div> </div> </div> @@ -279,7 +280,7 @@ <div class="col s12"> <div class="card"> <div class="card-image"> - {% if user.5 %}<img class="lazyload" data-src="{{ user.5 }}">{% endif %} + {% if user.medic.vac_certificate %}<img class="lazyload" data-src="{{ vac_file.0 }}{{ user.id }}{{ vac_file.1 }}">{% endif %} </div> </div> </div> @@ -292,7 +293,7 @@ </div> <div class="collapsible-body"><span> <ul class="collapsible"> - {% for doc in user.3 %} + {% for doc in request.user|user_docs:user.user %} <li> <div class="collapsible-header"><a onclick="send('f{{doc.id}}')">{{doc.document_type.name}}</a></div> </li> diff --git a/server/views.py b/server/views.py index 54f1352..0cdcf2a 100644 --- a/server/views.py +++ b/server/views.py @@ -270,9 +270,7 @@ def ulist(request): user = User.objects.get(id=request.POST["action"][1:])
# check if user has permission to deapprove user
if user.groups.all()[0] == group:
- content_type = ContentType.objects.get_for_model(Document)
- permission = Permission.objects.get(
- content_type=content_type, codename="approved")
+ permission = Permission.objects.get(codename="approved")
user.user_permissions.remove(permission)
return HttpResponseRedirect("ulist")
# make user "capo"
@@ -290,35 +288,18 @@ def ulist(request): return HttpResponseRedirect("ulist")
# list users with their documents
- users = list(User.objects.filter(
- groups__name=parent_group).filter(groups__name="capi").order_by("first_name"))
- users += list(User.objects.filter(
- groups__name=parent_group).exclude(groups__name="capi").order_by("first_name"))
- out = []
- for user in users:
- # list only approved users
- if not user.has_perm("client.approved") and not user.is_staff:
- continue
+ permission = Permission.objects.get(codename="approved")
- usercode = UserCode.objects.filter(user=user)[0]
- # get all user documents
- documents = Document.objects.filter(Q(user=user) & ~Q(
- status='archive') & Q(group__name=parent_group))
+ usercodes = UserCode.objects.filter(Q(user__user_permissions=permission) | Q(user__is_staff=True)).select_related("user", "medic").order_by("user__last_name")
- # generate link for images
- vac_file = ""
- health_file = ""
- if usercode.medic:
- if usercode.medic.vac_certificate.name:
- vac_file = "/server/media/" + str(usercode.id) + "/vac_certificate/usercode"
+ vac_file = ["/server/media/", "/vac_certificate/usercode"]
+ health_file = ["/server/media/", "/health_care_certificate/usercode"]
- if usercode.medic.health_care_certificate.name:
- health_file = "/server/media/" + str(usercode.id) + "/health_care_certificate/usercode"
-
- out.append([user, usercode, parent_group,
- documents, vac_file, health_file, "capi" in user.groups.values_list('name',flat = True)])
-
- context = {'users': out}
+ context = {
+ 'users': usercodes,
+ 'vac_file': vac_file,
+ 'health_file': health_file,
+ }
return render(request, 'server/user_list.html', context)
@@ -385,14 +366,14 @@ def doctype(request): return docedit_wrapper(request, context)
# check if request to download
- elif request.POST["action"][0] == 'd':
+ elif request.POST["action"][0] == 'p':
document_type = DocumentType.objects.get(id=request.POST["action"][1:])
# check if user has permission on the document
if document_type.group.name not in parent_groups:
return
- docs = Document.objects.filter(document_type=document_type)
+ docs = Document.objects.filter(document_type=document_type).select_related("personal_data", "medical_data", "user")
# get time for filename
current_time = datetime.strftime(datetime.now(), "%H_%M__%d_%m_%y")
@@ -519,26 +500,23 @@ def doctype(request): docc = DocumentType.objects.get(id=i)
# check if user has permission
if docc.group.name in parent_groups:
- selected.append(docc)
+ # execute action
+ if request.POST["action"] == 'delete':
+ try:
+ docc.delete()
+ except ProtectedError:
+ error = True
+ error_text = "Non puoi eliminare un tipo a cui é collegato uno o piú documenti"
+ elif request.POST["action"] == 'hide':
+ docc.enabled = False
+ docc.save()
+ elif request.POST["action"] == 'show':
+ docc.enabled = True
+ docc.save()
else:
error = True
error_text = "Non puoi modificare un documento non del tuo gruppo"
- # execute action on selected types
- for i in selected:
- if request.POST["action"] == 'delete':
- try:
- i.delete()
- except ProtectedError:
- error = True
- error_text = "Non puoi eliminare un tipo a cui é collegato uno o piú documenti"
- elif request.POST["action"] == 'hide':
- i.enabled = False
- i.save()
- elif request.POST["action"] == 'show':
- i.enabled = True
- i.save()
-
# check which filters are applied
public = "filter_public" in request.POST
selfsign = "filter_selfsign" in request.POST
@@ -561,9 +539,7 @@ def doctype(request): group_bool = True
# get documents from the list
- q_obj = Q()
- for i in parent_groups:
- q_obj |= Q(group__name=i)
+ q_obj = Q(group__name__in=parent_groups)
public_types = DocumentType.objects.filter(q_obj)
@@ -945,31 +921,30 @@ def doclist(request): if docc.group.name in parent_groups:
selected.append(docc)
- # execute action on selected documents
- for i in selected:
- if request.POST["action"] == 'delete' and settings.DEBUG:
- i.delete()
- elif request.POST["action"] == 'approve' and settings.DEBUG:
- i.status = 'ok'
- i.save()
- elif request.POST["action"] == 'archive':
- if i.status == 'ok':
- i.status = 'archive'
- if i.medical_data:
- i.medical_data.delete()
- i.medical_data.save()
- i.medical_data = None
- i.save()
- else:
- error = True
- error_text = "Non puoi archiviare un documento non approvato"
- elif request.POST["action"] == 'unarchive':
- if i.status == 'archive':
- i.status = 'ok'
- i.save()
- else:
- error = True
- error_text = "Non puoi dearchiviare un documento non archiviato"
+ # execute action on selected documents
+ if request.POST["action"] == 'delete' and settings.DEBUG:
+ docc.delete()
+ elif request.POST["action"] == 'approve' and settings.DEBUG:
+ docc.status = 'ok'
+ docc.save()
+ elif request.POST["action"] == 'archive':
+ if docc.status == 'ok':
+ docc.status = 'archive'
+ if docc.medical_data:
+ docc.medical_data.delete()
+ docc.medical_data.save()
+ docc.medical_data = None
+ docc.save()
+ else:
+ error = True
+ error_text = "Non puoi archiviare un documento non approvato"
+ elif request.POST["action"] == 'unarchive':
+ if docc.status == 'archive':
+ docc.status = 'ok'
+ docc.save()
+ else:
+ error = True
+ error_text = "Non puoi dearchiviare un documento non archiviato"
# get filter values
hidden = "filter_hidden" in request.POST
@@ -998,9 +973,7 @@ def doclist(request): groups = []
# filter documents based on group of staff
- q_obj = Q()
- for i in parent_groups:
- q_obj |= Q(group__name=i)
+ q_obj = Q(group__name__in=parent_groups)
documents = Document.objects.filter(q_obj)
@@ -1026,34 +999,26 @@ def doclist(request): # filter types, owner, groups using chips
if len(types) > 0:
if types[0] != "":
- q_obj = Q()
- for t in types:
- q_obj |= Q(document_type__name=t)
- chips_types.append(t)
-
+ q_obj = Q(document_type__name__in=types)
+ chips_types += types
documents = documents.filter(q_obj)
if len(owner) > 0:
if owner[0] != "":
- q_obj = Q()
- for u in owner:
- user = u.split("(")[0][:-1]
- q_obj |= Q(user__username=user)
- chips_owner.append(u)
-
+ q_obj = Q(user__username__in=list(map(lambda x: x.split("(")[0][:-1], owner)))
+ chips_owner += owner
documents = documents.filter(q_obj)
if len(groups) > 0:
if groups[0] != "":
- q_obj = Q()
- for g in groups:
- q_obj |= Q(group__name=g)
- chips_groups.append(g)
-
+ q_obj = Q(group__name__in=groups)
+ chips_groups += groups
documents = documents.filter(q_obj)
out = []
users = []
+
+ # TODO convert this in a query
for i in documents:
# filter for confirmed with attachment documents and approved
if signdoc:
@@ -1287,34 +1252,25 @@ def doclist_readonly(request): # filter types, owner, groups using chips
if len(types) > 0:
if types[0] != "":
- q_obj = Q()
- for t in types:
- q_obj |= Q(document_type__name=t)
- chips_types.append(t)
-
+ q_obj = Q(document_type__name__in=types)
+ chips_types += types
documents = documents.filter(q_obj)
if len(owner) > 0:
if owner[0] != "":
- q_obj = Q()
- for u in owner:
- user = u.split("(")[0][:-1]
- q_obj |= Q(user__username=user)
- chips_owner.append(u)
-
+ q_obj = Q(user__username__in=list(map(lambda x: x.split("(")[0][:-1], owner)))
+ chips_owner += owner
documents = documents.filter(q_obj)
if len(groups) > 0:
if groups[0] != "":
- q_obj = Q()
- for g in groups:
- q_obj |= Q(group__name=g)
- chips_groups.append(g)
-
+ q_obj = Q(group__name__in=groups)
+ chips_groups += groups
documents = documents.filter(q_obj)
out = []
users = []
+ # TODO user query instead of for
for i in documents:
# filter for confirmed with attachment documents and approved
if signdoc:
@@ -1584,19 +1540,15 @@ def data_request(request): parent_group = request.user.groups.values_list('name', flat=True)[0]
if request.method == "POST":
- if request.POST["request"] == "email_all":
- users = User.objects.filter(groups__name=parent_group)
- data = ""
- for user in users:
- data += user.email + ", "
- data = data[:-2]
+ if "request" not in request.POST.keys():
+ context["error"] = "Selezionare una richesta"
+ elif request.POST["request"] == "email_all":
+ users_email = User.objects.filter(groups__name=parent_group).values_list("email", flat=True)
+ data = ", ".join(users_email)
context["data"] = data
elif request.POST["request"] == "email_non_staff":
- users = User.objects.filter(groups__name=parent_group).exclude(groups__name="capi")
- data = ""
- for user in users:
- data += user.email + ", "
- data = data[:-2]
+ users_email = User.objects.filter(groups__name=parent_group).exclude(groups__name="capi").values_list("email", flat=True)
+ data = ", ".join(users_email)
context["data"] = data
elif request.POST["request"] == "data_user":
users = User.objects.filter(groups__name=parent_group)
diff --git a/version.txt b/version.txt index 1c220c3..28bb89b 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.3 -rev=10 +rev=11 |