diff --git a/sapl/protocoloadm/urls.py b/sapl/protocoloadm/urls.py index 0fca1b76b..2e3e07ac1 100644 --- a/sapl/protocoloadm/urls.py +++ b/sapl/protocoloadm/urls.py @@ -24,7 +24,8 @@ from sapl.protocoloadm.views import (AcompanhamentoDocumentoView, DesvincularMateriaView, AnexadoCrud, DocumentoAnexadoEmLoteView, PrimeiraTramitacaoEmLoteAdmView, - TramitacaoEmLoteAdmView) + TramitacaoEmLoteAdmView, + apaga_protocolos_view) from .apps import AppConfig @@ -107,6 +108,10 @@ urlpatterns_protocolo = [ url(r'^protocoloadm/tramitacao-em-lote', TramitacaoEmLoteAdmView.as_view(), name='tramitacao_em_lote_docadm'), + url(r'^protocoloadm/apaga_protocolos', apaga_protocolos_view, + name='apaga_protocolos_view'), + + ] urlpatterns_sistema = [ diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 6855ee9f5..b61b91ff8 100755 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -23,6 +23,7 @@ from django.views.generic import ListView, CreateView, UpdateView from django.views.generic.base import RedirectView, TemplateView from django.views.generic.edit import FormView from django_filters.views import FilterView +from django.contrib.admin.views.decorators import staff_member_required import sapl from sapl.base.email_utils import do_envia_email_confirmacao @@ -34,12 +35,15 @@ from sapl.crud.base import (Crud, CrudAux, MasterDetailCrud, make_pagination, from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa, UnidadeTramitacao from sapl.materia.views import gerar_pdf_impressos from sapl.parlamentares.models import Legislatura, Parlamentar -from sapl.protocoloadm.models import Protocolo +from sapl.protocoloadm.models import Protocolo, DocumentoAdministrativo from sapl.relatorios.views import relatorio_doc_administrativos from sapl.utils import (create_barcode, get_base_url, get_client_ip, get_mime_type_from_file_extension, lista_anexados, show_results_filter_set, mail_service_configured, from_date_to_datetime_utc) +from django.shortcuts import render + + from .forms import (AcompanhamentoDocumentoForm, AnularProtocoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoFilterSet, @@ -1731,3 +1735,48 @@ class TramitacaoEmLoteAdmView(PrimeiraTramitacaoEmLoteAdmView): status=status, unidade_tramitacao_destino=destino).distinct().values_list( 'documento_id', flat=True) + + +def apaga_protocolos(request, ano,numero_protocolo=None): + kwargs = {'ano__in':ano} + if numero_protocolo: + kwargs.update({'numero__gte':numero_protocolo}) + + all_protocolos = Protocolo.objects.filter(**kwargs) + + for doc in DocumentoAdministrativo.objects.filter(protocolo__in=all_protocolos): + doc.protocolo = None + doc.save() + + for ml in MateriaLegislativa.objects.filter(ano__in=ano, numero_protocolo__in=all_protocolos.values_list('numero')): + ml.numero_protocolo = None + ml.save() + + for deleted_object in all_protocolos: + post_delete_signal.send(sender=None, + instance=deleted_object, + operation='D', + request=request + ) + all_protocolos.delete() + + +@staff_member_required +def apaga_protocolos_view(request): + if request.method == "GET": + if Protocolo.objects.exists(): + intervalo_data = Protocolo.objects.all().distinct('ano').values_list('ano', flat=True).order_by('-ano') + else: + intervalo_data = None + return render(request,"protocoloadm/deleta_todos_protocolos.html",{'intervalo_data':intervalo_data}) + + elif request.method == "POST": + password = request.POST.get('senha') + valid = request.user.check_password(password) + if valid: + anos = request.POST.getlist('ano') + numero_protocolo = request.POST.get('numero_protocolo') + apaga_protocolos(request,anos,numero_protocolo) + return JsonResponse({'type':'success','msg':''}) + else: + return JsonResponse({'type':'error','msg':'Senha Incorreta'}) \ No newline at end of file diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index 9a9c40d8d..84dbde48a 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -185,3 +185,6 @@ - title: {% trans 'Status de Tramitação' %} url: sapl.protocoloadm:statustramitacaoadministrativo_list css_class: btn btn-link + - title: {% trans 'Apagar Todos Protocolos' %} + url: sapl.protocoloadm:apaga_protocolos_view + css_class: btn btn-link \ No newline at end of file diff --git a/sapl/templates/protocoloadm/deleta_todos_protocolos.html b/sapl/templates/protocoloadm/deleta_todos_protocolos.html new file mode 100644 index 000000000..6cbac5c45 --- /dev/null +++ b/sapl/templates/protocoloadm/deleta_todos_protocolos.html @@ -0,0 +1,127 @@ +{% extends "base.html" %} +{% load i18n crispy_forms_tags %} + +{% block base_content %} + +{% if intervalo_data %} + + +
+ + + + + + +
+ +
+
+ Cancelar + + +
+ + +{% else %} +

Não há registros de protocolos.

+ Voltar para tabelas auxiliares. +{% endif %} + + + + + +{% endblock base_content %} + +{% block extra_js %} + + + +{% endblock extra_js%}