Ver código fonte

selezione multipla

mauro 10 meses atrás
pai
commit
a76a67ba28
2 arquivos alterados com 31 adições e 2 exclusões
  1. 6 1
      utente/templates/utente.welcome.html
  2. 25 1
      utente/views.py

+ 6 - 1
utente/templates/utente.welcome.html

@@ -5,7 +5,8 @@
   <div class='form-control'>
     {% if admin.crea_utente %} 
       <input type='submit' class="btn btn-primary" name='scelta' value='Nuovo Dipendente'>
-      <button type='button' class="btn btn-primary" name='TastoCaricaIndici' data-bs-toggle='modal' data-bs-target='#CaricaIndiceModal'>Carica Lista Nuovi Dipendenti<button>
+      <button type='button' class="btn btn-primary" name='TastoCaricaIndici' data-bs-toggle='modal' data-bs-target='#CaricaIndiceModal'>Carica Lista Nuovi Dipendenti</button>
+      <button type='submit' class="btn btn-primary" name='ScaricaSelezionati' value="ScaricaSelezionati">Scarica Selezionati</button>
     {% endif %}
     <input type='submit' class="btn btn-primary" name="indietro" value="Indietro">
   </div>
@@ -29,6 +30,7 @@
   	  <th scope='col'>Pin</th>
         {% endif %}
         <th scope='col'>Inserimento</th>
+	<th scope='col'><input class="form-check-input" type="checkbox" id="select" name="select" value='0'/></th>
       </tr>
     </thead>
     <tbody>
@@ -49,6 +51,9 @@
             <td> {{ uu.pin }} </td>
           {% endif %}
           <td> {{ uu.inserimento|date:'d/m/Y' }} </td>
+	  <td>
+		  <input class="form-check-input" type="checkbox" id="select" name="select" value='{{ uu.id }}'/>
+          </td>
 	</tr>
       {% endfor %} 
     </tbody>

+ 25 - 1
utente/views.py

@@ -15,6 +15,9 @@ from random import randint
 from config.views import *
 import re
 
+import csv
+from io import StringIO
+
 def welcome(request):
   if not 'AdminId' in request.session or 'UserId' in request.session:
     print("Non rilevo presensa UserId e AdminId in request.session")
@@ -54,6 +57,10 @@ def welcome(request):
   if request.method == 'POST':
     print('qualcuno ha premuto un tasto')
 
+    print("***********")
+    print(request.POST)
+    print("***********")
+
     if 'indietro' in request.POST:
       return HttpResponseRedirect(reverse("azienda:welcome"))
 
@@ -77,7 +84,22 @@ def welcome(request):
           save_and_load_file_indice(request,fileindiceottenuto,data['azienda'],data['sede'])
         else:
           print('request non valida')
-        
+      if 'select' in request.POST:
+        select = request.POST.get('select')
+        print('select',select,type(select))
+        tmplist = list()
+        for i in select:
+          print("utente",i)
+          if i == '0': continue
+          u = Utente.objects.get(pk=int(i))
+          tmplist.append([u.codicefiscale,u.nome,u.pin])
+          print("lunghezza tmplist",len(tmplist))
+
+        f = StringIO()
+        csv.writer(f).writerows(tmplist)
+        print(f.getvalue())
+
+          
   return render(request,'utente.welcome.html',data)
 
 def edit(request):
@@ -340,7 +362,9 @@ def updatePasswordFromLogin(request,uuid):
   print('uuid',uuid)
 
   if request.method == 'POST':
+    print("***********")
     print(request.POST)
+    print("***********")
     formupdatepasswordlogin = formUpdatePasswordLogin(request.POST)
     if formupdatepasswordlogin.is_valid():
       cfisc = formupdatepasswordlogin.cleaned_data.get('cfisc')