Browse Source

merge manuale di comunicazione - aggiunte le modifiche fatte in documento

Mauro 1 năm trước cách đây
mục cha
commit
55fc3fb361
4 tập tin đã thay đổi với 86 bổ sung27 xóa
  1. 2 2
      .gitignore
  2. 4 0
      documento/forms.py
  3. 49 21
      documento/templates/documento.welcome.html
  4. 31 4
      documento/views.py

+ 2 - 2
.gitignore

@@ -2,6 +2,6 @@
 *.log
 *.bak
 *~
-db.sqlite3
+db/db.sqlite3
 *.saved
-settings.py
+db/settings.py

+ 4 - 0
documento/forms.py

@@ -23,3 +23,7 @@ class AdminUpload(forms.Form):
     self.fields['allegati'] = MultipleFileField(required=False)
     self.fields['descrizione'] = forms.CharField(required=False)
 
+class DeleteOldDocuments(forms.Form):
+  def __init(self,*args,**kwargs):
+    forms.Form.__init__(self,*args,**kwargs)
+    self.fields['limite'] = forms.CharField(required=True)

+ 49 - 21
documento/templates/documento.welcome.html

@@ -29,6 +29,7 @@
 
     {% endif %}
 
+  
   {% if ElencoDocumentiPerAzienda %}
     <table class='table table-striped table-hover'>
       <thead class='thead-dark'>
@@ -71,7 +72,7 @@
              <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
              <form name='ConfirmDeleteModal' method='POST'>
                {% csrf_token %}
-               <button type="submit" name="DeleteDocument" value='{{ documento.id }}' class="btn btn-primary">Conferma</button>
+               <button type="submit" name="DeleteDocument" value='{{ documento.id }}' class="btn btn-primary"></button>
              </form>
            </div>
          </div>
@@ -94,30 +95,57 @@
       <h5 class="card-title">Upload Indici e Documenti</h5>
       <form name='upload' method='post' enctype='multipart/form-data'>
         {% csrf_token %}
-
-        <table class='table table-striped table-hover'>
-          <tbody>
-            <tr>
-              <td><label for='indice'>Indice Utenti:&nbsp;</label>
-                <input type='file' class="btn btn-primary" name='indice' id='indice' value='{{ uf.indice }}' accept='text/csv'></td>
-
-              <td><label for='descrizione'>Descrizione:&nbsp;</label>
-                  <input type='text' name='descrizione' id='descrizione' value=''>
-                  <input type='file' class="btn btn-primary" name='allegati' id='allegati' value='{{ uf.allegati }}' accept='application/pdf' multiple></td>
-            </tr>
-          </table>
-          <table>
-            <tr>
-              <td><input type='submit' class="btn btn-primary" value='Inserisci'><td>
-              <td><input type='submit' class="btn btn-primary" name='ritorna' value='Ritorna'></td>
-            </tr>
-          </table>
-        </tbody>
+	<div class='form-group form-inline'>
+	  <label for='indice'>Indice Utenti:&nbsp;</label>
+          <input type='file' class="btn btn-primary" name='indice' id='indice' value='{{ uf.indice }}' accept='text/csv'>
+          <input type='file' class="btn btn-primary" name='allegati' id='allegati' value='{{ uf.allegati }}' accept='application/pdf' multiple>
+        </div>
+	<div><br></div>
+	<div class='form-group form-inline'>
+          <label for='descrizione'>Descrizione:&nbsp;</label>
+          <input type='text' name='descrizione' id='descrizione' value='' maxlength='120' size='80'>
+        </div>
+	<div><br></div>
+	<div class='form-group form-inline'>
+	  <input type='submit' class="btn btn-primary" value='Carica Nuovi Documenti'>
+	  <input type='submit' class="btn btn-primary" name='Ritorna' value='Ritorna'>
+          <button type='button' class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#ConfirmDocumentDeleteModal'>Elimina Vecchi Documenti</button></td>
+        </div>
       </form>
     </div>
   </div>
 
-  <div><br><br></div>
+  <!-- Modal -->
+  <div class="modal fade" id="ConfirmDocumentDeleteModal" tabindex="-1" role="dialog" aria-labelledby="ConfirmDocumentDeleteLabel{{ document.id }}" aria-hidden="true">
+         <div class="modal-dialog" role="document">
+           <div class="modal-content">
+             <form name='ConfirmDeleteModal' method='POST'>
+               {% csrf_token %}
+               <div class="modal-header">
+                <h5 class="modal-title" id="ConfirmDeleteLabel">Conferma Cancellazione</h5>
+                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
+                  <span aria-hidden="true">&times;</span>
+                </button>
+               </div>
+               <div class="modal-body">
+               Confermi la cancellazione dei vecchi documenti?<br>
+               La cancellazione è definitiva,immediata e non recuperabile
+               <label for='limite'>Documenti più vecchi di:&nbsp;</label>
+               <input type='text' name='limite' id='limite' value='{{ eol }}' maxlenght='4' size='4'>
+               <label for='limite'>giorni.</label>
+               </div>
+               <div class="modal-footer">
+               <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+               <button type="submit" name="DeleteOldDocuments" value='{{ documento.id }}' class="btn btn-primary">Elimina Vecchi Documenti</button>
+	       </div>
+	     </form>
+           </div>
+         </div>
+       </div>
+     </div>
+     <!-- end modal -->
+ 
+  <div><br></div>
 
 
   {% if listaok %}

+ 31 - 4
documento/views.py

@@ -14,6 +14,8 @@ from config.views import *
 from .managefile import *
 from att.views import *
 
+from datetime import datetime,timedelta
+
 def welcome(request):
   '''
   punto di ingresso.
@@ -55,11 +57,36 @@ def welcome(request):
   utenti = Utente.objects.filter(azienda = azienda)  
   data['utenti'] = utenti
 
+  eol = getConfig('DocEol')
+  data['eol'] = eol
+
   if request.method == 'POST':
 
     if 'ritorna' in request.POST:
       return HttpResponseRedirect(reverse("azienda:welcome"))
 
+    if 'DeleteOldDocuments' in request.POST:
+      print('Richiesta di eliminazione vecchi documenti')
+      dods = DeleteOldDocuments(request.POST)
+      if dods.is_valid():
+        print('request',request.POST)
+        print('dods',dods.cleaned_data)
+        print(request.POST['limite'])
+        print('effettuata scelta di cancellazione vecchi documenti')
+        # costuire una lista dei documenti più vecchi
+        limite = int(request.POST['limite'])
+        print('limite',limite)
+        d = datetime.now()
+        r = d - timedelta(days=limite)
+        print(r)
+        oldDocs = Documento.objects.filter(azienda=azienda)
+        oldDocs1 = oldDocs.filter(dataupload__lt=r)
+        print('lista documenti',len(oldDocs1))
+        for i in oldDocs1:
+          print('documento',i.documento)
+          delete_file(i)
+          i.delete()
+
     if 'DeleteDocument' in request.POST:
       print('Richiesta cancellazione Documento',request.POST)
       documento = request.POST['DeleteDocument']  # perche' lo considera una lista e non un singolo valore?
@@ -67,7 +94,6 @@ def welcome(request):
       try:
         d = Documento.objects.get(pk=documento)
         delete_file(d)  #rimozione fisica del documento 
-        setLog(5,documento,admin)
         d.delete()
       except Documento.DoesNotExist as dne:
         print('il documento non esiste')
@@ -149,8 +175,9 @@ def finalize_download(request,did,uid=None):
 
   mime_type, _ = mimetypes.guess_type(fl_completa)
   fl = fl_completa
-  print('fl',fl,mime_type,'fn',documento.documento)
-  response = FileResponse(open(fl,'rb'),content_type='application/pdf',filename="%s" % documento.documento,as_attachment=False)
-  setLog(3,utente=utente,documento=documento,azienda=utente.azienda)
+  print('fl',fl,mime_type)
+  response = FileResponse(open(fl,'rb'),content_type='application/pdf',as_attachment=False)
+  #response['Content-Disposition'] = "attachment; filename=%s" % documento.documento
+  setNewLog(3,{'utente':utente,'documento':documento,'azienda':utente.azienda})
   return response