Browse Source

HOT-FIX: Adiciona validação de tamanho de arquivo em acessório em lote

pull/2894/head
Cesar Carvalho 6 years ago
parent
commit
757c8c081b
  1. 9
      sapl/materia/views.py
  2. 10
      sapl/templates/materia/em_lote/acessorio.html

9
sapl/materia/views.py

@ -51,7 +51,7 @@ from sapl.materia.forms import (AnexadaForm, AutoriaForm,
from sapl.norma.models import LegislacaoCitada from sapl.norma.models import LegislacaoCitada
from sapl.parlamentares.models import Legislatura from sapl.parlamentares.models import Legislatura
from sapl.protocoloadm.models import Protocolo from sapl.protocoloadm.models import Protocolo
from sapl.settings import MEDIA_ROOT from sapl.settings import MEDIA_ROOT, MAX_DOC_UPLOAD_SIZE
from sapl.utils import (YES_NO_CHOICES, autor_label, autor_modal, SEPARADOR_HASH_PROPOSICAO, from sapl.utils import (YES_NO_CHOICES, autor_label, autor_modal, SEPARADOR_HASH_PROPOSICAO,
gerar_hash_arquivo, get_base_url, get_client_ip, gerar_hash_arquivo, get_base_url, get_client_ip,
get_mime_type_from_file_extension, montar_row_autor, get_mime_type_from_file_extension, montar_row_autor,
@ -2118,6 +2118,13 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView):
messages.add_message(request, messages.ERROR, msg) messages.add_message(request, messages.ERROR, msg)
return self.get(request, self.kwargs) return self.get(request, self.kwargs)
if request.FILES['arquivo'].size > MAX_DOC_UPLOAD_SIZE:
msg = _("O arquivo Anexo de Texto Integral deve ser menor que {0:.1f} MB, \
o tamanho atual desse arquivo é {1:.1f} MB" \
.format((MAX_DOC_UPLOAD_SIZE/1024)/1024, (request.FILES['arquivo'].size/1024)/1024))
messages.add_message(request, messages.ERROR, msg)
return self.get(request, self.kwargs)
tmp_name = os.path.join(MEDIA_ROOT, request.FILES['arquivo'].name) tmp_name = os.path.join(MEDIA_ROOT, request.FILES['arquivo'].name)
with open(tmp_name, 'wb') as destination: with open(tmp_name, 'wb') as destination:
for chunk in request.FILES['arquivo'].chunks(): for chunk in request.FILES['arquivo'].chunks():

10
sapl/templates/materia/em_lote/acessorio.html

@ -22,7 +22,7 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label>Tipo*</label> <label>Tipo*</label>
<select name="tipo" class="form-control" required="True"> <select name="tipo" class="form-control" required="true">
{% for t in tipos_docs %} <option>{{t}}</option> {% endfor %} {% for t in tipos_docs %} <option>{{t}}</option> {% endfor %}
</select> </select>
</div> </div>
@ -31,14 +31,14 @@
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label>Nome*</label> <label>Nome*</label>
<input type="text" name="nome" class="form-control" required="True"> <input type="text" name="nome" class="form-control" required="true">
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="form-group"> <div class="form-group">
<label>Data*</label> <label>Data*</label>
<input type="text" name="data" class="form-control dateinput" required="True"> <input type="text" name="data" class="form-control dateinput" required="true">
</div> </div>
</div> </div>
</div> </div>
@ -47,7 +47,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label>Autor:</label> <label>Autor:</label>
<input type="text" name="autor" class="form-control" required="False"> <input type="text" name="autor" class="form-control" required="false">
</div> </div>
</div> </div>
</div> </div>
@ -65,7 +65,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label>Texto Integral*</label> <label>Texto Integral*</label>
<input type="file" name="arquivo" required="True"> <input type="file" name="arquivo" required="true">
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save