|
|
@@ -19,6 +19,9 @@ import re
|
|
|
import csv
|
|
|
from io import StringIO
|
|
|
|
|
|
+from codicefiscale import codicefiscale
|
|
|
+from collections import Counter
|
|
|
+
|
|
|
def OrdinaUtenti(rq=None,ou=None):
|
|
|
tmp=None
|
|
|
print("len(ou)",len(ou))
|
|
|
@@ -67,7 +70,10 @@ def welcome(request):
|
|
|
else:
|
|
|
data['AziendaId'] = request.session['AziendaId']
|
|
|
data['azienda'] = Azienda.objects.get(pk=data['AziendaId'])
|
|
|
+
|
|
|
+ # ottiene tutti gli utenti relativi all'azienda
|
|
|
data['utenti'] = data['azienda'].utente_set.all().order_by('nome').filter(special=False)
|
|
|
+
|
|
|
data['numeroRecordAzienda'] = len(data['utenti'])
|
|
|
|
|
|
if 'AdminId' in request.session:
|
|
|
@@ -93,6 +99,7 @@ def welcome(request):
|
|
|
data['UserId'] = request.session['UserId']
|
|
|
|
|
|
data['utenti'] = OrdinaUtenti(request,data['utenti'])
|
|
|
+
|
|
|
try:
|
|
|
data['numeroRecordAttuali'] = len(data['utenti'])
|
|
|
except TypeError as te:
|
|
|
@@ -138,6 +145,20 @@ def welcome(request):
|
|
|
else:
|
|
|
print('request non valida')
|
|
|
|
|
|
+ if 'cerca' in request.POST:
|
|
|
+ print('premuto tasto cerca')
|
|
|
+ formcerca = formCerca(request.POST)
|
|
|
+ if formcerca.is_valid():
|
|
|
+ valoredacercare = formcerca.cleaned_data.get('valoredacercare')
|
|
|
+ else:
|
|
|
+ print('form non valida')
|
|
|
+ print('richiesta da cercare',valoredacercare)
|
|
|
+ nome = data['utenti'].filter(nome__icontains=valoredacercare)
|
|
|
+ codicefiscale = data['utenti'].filter(codicefiscale__icontains=valoredacercare)
|
|
|
+ data['formcerca'] = formcerca
|
|
|
+ data['utenti'] = dict(Counter(nome) + Counter(codicefiscale))
|
|
|
+
|
|
|
+
|
|
|
if 'MultipleCSVSelect' in request.POST:
|
|
|
#validiamo i dati passati
|
|
|
SelectResponse = formMultipleCheckBoxCSVDOC(request.POST,lista=data['utenti'])
|
|
|
@@ -308,6 +329,7 @@ def edit(request):
|
|
|
return HttpResponseRedirect(reverse("utente:cancellautente"))
|
|
|
|
|
|
print('i dati sono grosso modo coerenti, salviamoli')
|
|
|
+ old_utente_codicefiscale = utente.codicefiscale
|
|
|
utente.nome = fu.cleaned_data['nome'].title()
|
|
|
utente.codicefiscale = fu.cleaned_data['codicefiscale'].upper()
|
|
|
utente.luogonascita = fu.cleaned_data['luogonascita'].title()
|
|
|
@@ -328,17 +350,28 @@ def edit(request):
|
|
|
print('sede non valida',tmp_sede)
|
|
|
print('utente da registrare',utente.nome,utente.sede_id)
|
|
|
setLog(7,utente=utente)
|
|
|
+
|
|
|
+ new_utente_codicefiscale = None
|
|
|
try:
|
|
|
utente.save()
|
|
|
- print('utente: salvo record {}'.format(utente.codicefiscale))
|
|
|
- return HttpResponseRedirect(reverse("utente:welcome"))
|
|
|
+ print('utente, salvo record {}'.format(utente.codicefiscale))
|
|
|
+ new_utente_codicefiscale = utente.codicefiscale
|
|
|
+ print('new_utente.codicefiscale',new_utente_codicefiscale,old_utente_codicefiscale)
|
|
|
+ if new_utente_codicefiscale:
|
|
|
+ if new_utente_codicefiscale != old_utente_codicefiscale:
|
|
|
+ print('codice fiscale diverso:',old_utente_codicefiscale,new_utente_codicefiscale)
|
|
|
+ rename_dir(utente,old_utente_codicefiscale,new_utente_codicefiscale)
|
|
|
except IntegrityError as ie:
|
|
|
print('utente: errore utente presente: {}'.format(utente.codicefiscale))
|
|
|
utenteIE = Utente.objects.get(codicefiscale=fu.cleaned_data['codicefiscale'])
|
|
|
print(utenteIE.nome)
|
|
|
data['IntegrityError']=utenteIE
|
|
|
+ utenteesistente = Utente.objects.get(codicefiscale=utente.codicefiscale)
|
|
|
+ data['codicefiscaleesistente'] = utenteesistente.azienda.nome
|
|
|
|
|
|
- print('Form non valida')
|
|
|
+
|
|
|
+ print('Form non valida,altro ciclo')
|
|
|
+ utente = Utente.objects.get(pk=data['UserEditId'])
|
|
|
tmp = dict()
|
|
|
tmp['nome'] = utente.nome
|
|
|
tmp['codicefiscale'] = utente.codicefiscale
|
|
|
@@ -437,6 +470,11 @@ def edit(request):
|
|
|
print("Mail non valida")
|
|
|
data['mailnonvalida']=True
|
|
|
|
|
|
+ #verifica bonta' codicefiscale
|
|
|
+ if not codicefiscale.is_valid(utente.codicefiscale):
|
|
|
+ print('codice fiscale tecnicamente non valido')
|
|
|
+ data['codicefiscalenonvalido'] = True
|
|
|
+
|
|
|
return render(request,'utente.edit.html',data)
|
|
|
|
|
|
def download(request):
|