|
|
@@ -85,21 +85,34 @@ def welcome(request):
|
|
|
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())
|
|
|
-
|
|
|
-
|
|
|
+ #validiamo i dati passati
|
|
|
+ SelectResponse = formMultipleCheckBox(request.POST)
|
|
|
+ SelectResponse.c(data['utenti'])
|
|
|
+ print("SelectResponse",SelectResponse)
|
|
|
+
|
|
|
+ if SelectResponse.is_valid():
|
|
|
+ select = SelectResponse.cleaned_data.get('select')
|
|
|
+ print('select',select,type(select))
|
|
|
+
|
|
|
+ tmplist = list()
|
|
|
+ tmplist.append(["Codice Fiscale","Nome","Pin"])
|
|
|
+ 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())
|
|
|
+
|
|
|
+ # scarica il file
|
|
|
+ response = FileResponse(f.getvalue(),content_type='application/csv',as_attachment=False)
|
|
|
+ response['Content-Disposition'] = 'attachment; filename="lista_dipendenti.csv"'
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
return render(request,'utente.welcome.html',data)
|
|
|
|
|
|
def edit(request):
|