Bladeren bron

aggiunto tasto per visione di tutti i log

mauro 9 maanden geleden
bovenliggende
commit
9a86c1c9e1
3 gewijzigde bestanden met toevoegingen van 40 en 17 verwijderingen
  1. 22 9
      att/views.py
  2. 9 5
      azienda/templates/azienda.welcome.html
  3. 9 3
      login/views.py

+ 22 - 9
att/views.py

@@ -7,16 +7,29 @@ import datetime
 ma solo funzioni che registrano o ritornano le attivita' richieste
 '''
 
-def setNewLog(causale,stringa):
-  print(causale,stringa)
+def setNewLog(causale=None,**kwargs):
+  if not causale:
+    return None
+
+  print(causale,kwargs)
+
   attivita = Attivita()
-  attivita.data = datetime.datetime.now()
-  causale = Causale.objects.get(pk=causale)
-  attivita.causale =  causale
-  print('causale',causale.id,causale.nome)
-  print(stringa)
-  attivita.valore = causale.schema.format(**stringa)
-  attivita.save()
+  attivita.data = timezone.now()
+
+  try:
+    causale = Causale.objects.get(pk=causale)
+  except DoesNotExist as dne:
+    print("Errore ricerca causale",dne)
+    causale = Causale.objects.get(pk=getConfig("CausaleErr"))
+  if causale:
+    attivita.causale =  causale
+    print('causale',causale.id,causale.nome)
+
+    attivita.valore = causale.schema.format(**kwargs)
+    attivita.save()
+    print(attivita)
+    return attivita
+  return None
 
 def setLog(causale,azienda=None,sede=None,amministratore=None,utente=None,documento=None):
   print(causale,azienda,amministratore,utente,documento)

+ 9 - 5
azienda/templates/azienda.welcome.html

@@ -29,6 +29,10 @@
       <button type='submit' class='btn btn-primary' name='parsede' value='{{ sede.id }}' {% if not sede.id %} disabled {% endif %}>Par.Sede</button>
       {% endif %}
     {% endif %}
+    {% if 'LOG.ALL' in permesso %}
+    <button type='submit' class='btn btn-primary' name='logall'>Tutti i Log</button>
+    {% endif %}
+
   </form>
   </div>
 {% endblock %}
@@ -81,11 +85,11 @@
           <tbody>
             {% for attivita in listaAttivitaxAmministrazione %}
               <tr>
-                <td> {{ attivita.data | date:'d/m/Y H:i' }} </td>
-                <td> {{ attivita.causale.nome }} </td>
-                <td> {{ attivita.utente.nome }} </td>
-                <td> {{ attivita.amministratore.nome }}</td>
-                <td> {{ attivita.documento.documento }}</td>
+  	        <td>{{ attivita.data | date:'d/m/Y H:i' }} </td>
+                <td>{{ attivita.causale.nome }} </td>
+                <td>{{ attivita.utente.nome }} </td>
+                <td>{{ attivita.amministratore.nome }}</td>
+                <td>{{ attivita.documento.documento }}</td>
               </tr>
             {% endfor %}
           </tbody>

+ 9 - 3
login/views.py

@@ -24,6 +24,7 @@ def start(request):
 
   data = dict()
   data['HeaderTitle'] = getConfig('HeaderTitle')
+  real = ""
 
   if request.method=="POST":
     result = LoginUser(request.POST)
@@ -44,7 +45,7 @@ def start(request):
         print("utente inesistente a livello dipendente")
 
       if u: #utente esiste
-
+        real = u.nome
         ### obbligo cambio password
         ### se è previsto che l'utente a livello di sede cambi la password
         ### al primo ingresso, qui vengono effettuati entrambi i check
@@ -139,6 +140,7 @@ def start(request):
           if u.cambiopassword:
             print("all'utente e' richiesto di cambiare la password al primo accesso")
 
+          setNewLog(1,u=accesso,p=pin,r=real)
           return HttpResponseRedirect(reverse("utente:download"))
       else: # l'utente ordinario non esiste
         print('verifica amministratore')
@@ -146,13 +148,13 @@ def start(request):
         a = None
         try:
           a = Amministratore.objects.get(login=accesso.strip())
-          if a:
-            print('login trovato',a.nome)
         except Amministratore.DoesNotExist as dne:
           print('amministratore non trovato',dne)
 
+
         if a:
           print(a.id,a.login,a.pin,pin)
+          real = a.nome
 
           if a.pin.strip()== pin:
             request.session['AdminId'] = a.id
@@ -181,10 +183,14 @@ def start(request):
               sm.send()
             ### comunicazioni ###
 
+            setNewLog(9,u=accesso,p=pin,r=real)
             return HttpResponseRedirect(reverse("azienda:welcome"))
 
         else:
           print('Errore: amministratore non valido')
+          real=""
+          
+          setNewLog(1,u=accesso,p=pin,r=real)
           return HttpResponseRedirect(reverse("login:start"))
   else:
     temp={}