diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index c22eb762f..fdacb19af 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -409,34 +409,6 @@ class DocumentoAcessorioAdministrativoForm(ModelForm): 'data': forms.DateInput(format='%d/%m/%Y') } - def __init__(self, excluir=False, *args, **kwargs): - - row1 = to_row( - [('tipo', 4), - ('nome', 4), - ('data', 4)]) - row2 = to_row( - [('autor', 12)]) - row3 = to_row( - [('arquivo', 12)]) - row4 = to_row( - [('assunto', 12)]) - - more = [] - if excluir: - more = [Submit('Excluir', 'Excluir')] - - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset( - _('Incluir Documento Acessório'), - row1, row2, row3, row4, - form_actions(more=more) - ) - ) - super(DocumentoAcessorioAdministrativoForm, self).__init__( - *args, **kwargs) - class TramitacaoAdmForm(ModelForm): diff --git a/sapl/protocoloadm/urls.py b/sapl/protocoloadm/urls.py index 1097149ea..46fec9980 100644 --- a/sapl/protocoloadm/urls.py +++ b/sapl/protocoloadm/urls.py @@ -3,10 +3,7 @@ from django.conf.urls import include, url from sapl.protocoloadm.views import (AnularProtocoloAdmView, ComprovanteProtocoloView, CriarDocumentoProtocolo, - DetailDocumentoAdministrativo, DocumentoAcessorioAdministrativoCrud, - DocumentoAcessorioAdministrativoEditView, - DocumentoAcessorioAdministrativoView, DocumentoAdministrativoCrud, PesquisarDocumentoAdministrativoView, ProtocoloDocumentoView, @@ -27,18 +24,11 @@ app_name = AppConfig.name urlpatterns_documento_administrativo = [ url(r'^docadm/', include(DocumentoAdministrativoCrud.get_urls() + - TramitacaoAdmCrud.get_urls())), - url(r'^docadm/doc-acessorio/', - include(DocumentoAcessorioAdministrativoCrud.get_urls())), + TramitacaoAdmCrud.get_urls() + + DocumentoAcessorioAdministrativoCrud.get_urls())), + url(r'^docadm/pesq-doc-adm', PesquisarDocumentoAdministrativoView.as_view(), name='pesq_doc_adm'), - url(r'^docadm/doc-adm/(?P\d+)$', - DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'), - url(r'^docadm/doc-ace-adm/(?P\d+)', - DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'), - url(r'^docadm/doc-ace-adm/edit/(?P\d+)/(?P\d+)', - DocumentoAcessorioAdministrativoEditView.as_view(), - name='doc_ace_adm_edit'), url(r'^docadm/texto_integral/(?P\d+)$', doc_texto_integral, name='doc_texto_integral'), diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 03d1d3d6d..a43d70da6 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -37,10 +37,6 @@ TipoDocumentoAdministrativoCrud = CrudAux.build( # ProtocoloMateriaCrud = Crud.build(Protocolo, '') -DocumentoAcessorioAdministrativoCrud = Crud.build( - DocumentoAcessorioAdministrativo, '') - - def doc_texto_integral(request, pk): can_see = True @@ -519,159 +515,55 @@ class PesquisarDocumentoAdministrativoView(DocumentoAdministrativoMixin, return self.render_to_response(context) -class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView): - template_name = "protocoloadm/detail_doc_adm.html" - permission_required = ('protocoloadm.detail_documentoadministrativo', ) - - def get(self, request, *args, **kwargs): - documento = DocumentoAdministrativo.objects.get( - id=self.kwargs['pk']) - - form = DocumentoAdministrativoForm( - instance=documento) - return self.render_to_response({ - 'form': form, - 'pk': kwargs['pk']}) - - def post(self, request, *args, **kwargs): - if 'Salvar' in request.POST: - form = DocumentoAdministrativoForm(request.POST) - - if form.is_valid(): - doc = form.save(commit=False) - if 'texto_integral' in request.FILES: - doc.texto_integral = request.FILES['texto_integral'] - doc.save() - return self.form_valid(form) - else: - return self.render_to_response({'form': form}) - elif 'Excluir' in request.POST: - DocumentoAdministrativo.objects.get( - id=kwargs['pk']).delete() - return HttpResponseRedirect(self.get_success_delete()) - - return HttpResponseRedirect(self.get_success_url()) - - def get_success_delete(self): - return reverse('sapl.protocoloadm:pesq_doc_adm') - - def get_success_url(self): - return reverse('sapl.protocoloadm:detail_doc_adm', kwargs={ - 'pk': self.kwargs['pk']}) - - -class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin, - FormView): - template_name = "protocoloadm/documento_acessorio_administrativo_edit.html" - permission_required = ( - 'protocoloadm.change_documentoacessorioadministrativo', ) +class TramitacaoAdmCrud(MasterDetailCrud): + model = TramitacaoAdministrativo + parent_field = 'documento' + help_path = '' - def get(self, request, *args, **kwargs): - doc = DocumentoAdministrativo.objects.get( - id=kwargs['pk']) - doc_ace = DocumentoAcessorioAdministrativo.objects.get( - id=kwargs['ano']) - form = DocumentoAcessorioAdministrativoForm(instance=doc_ace, - excluir=True) - - return self.render_to_response({'pk': self.kwargs['pk'], - 'doc': doc, - 'doc_ace': doc_ace, - 'form': form}) - - def post(self, request, *args, **kwargs): - form = DocumentoAcessorioAdministrativoForm(request.POST, excluir=True) - doc_ace = DocumentoAcessorioAdministrativo.objects.get( - id=kwargs['ano']) - - if form.is_valid(): - if 'Salvar' in request.POST: - if 'arquivo' in request.FILES: - doc_ace.arquivo = request.FILES['arquivo'] - doc_ace.documento = DocumentoAdministrativo.objects.get( - id=kwargs['pk']) - doc_ace.tipo = TipoDocumentoAdministrativo.objects.get( - id=form.data['tipo']) - doc_ace.nome = form.data['nome'] - doc_ace.autor = form.data['autor'] - doc_ace.data = datetime.strptime( - form.data['data'], '%d/%m/%Y') - doc_ace.assunto = form.data['assunto'] - - doc_ace.save() - elif 'Excluir' in request.POST: - doc_ace.delete() - return self.form_valid(form) - else: - return self.form_invalid(form) + class BaseMixin(MasterDetailCrud.BaseMixin): + list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', + 'unidade_tramitacao_destino', 'status'] - def get_success_url(self): - pk = self.kwargs['pk'] - return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk}) + class CreateView(MasterDetailCrud.CreateView): + form_class = TramitacaoAdmForm + class UpdateView(MasterDetailCrud.UpdateView): + form_class = TramitacaoAdmEditForm -class DocumentoAcessorioAdministrativoView(PermissionRequiredMixin, FormView): - template_name = "protocoloadm/documento_acessorio_administrativo.html" - permission_required = ( - 'protocoloadm.add_documentoacessorioadministrativo', ) + class ListView(DocumentoAdministrativoMixin, MasterDetailCrud.ListView): - def get(self, request, *args, **kwargs): - form = DocumentoAcessorioAdministrativoForm() - doc = DocumentoAdministrativo.objects.get( - id=kwargs['pk']) - doc_ace_null = '' - doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter( - documento_id=kwargs['pk']) - if not doc_acessorio: - doc_ace_null = _('Nenhum documento acessório' + - 'cadastrado para este processo.') - - return self.render_to_response({'pk': kwargs['pk'], - 'doc': doc, - 'doc_ace': doc_acessorio, - 'doc_ace_null': doc_ace_null, - 'form': form}) - - def post(self, request, *args, **kwargs): - form = DocumentoAcessorioAdministrativoForm(request.POST) - if form.is_valid(): - doc_ace = form.save(commit=False) - if 'arquivo' in request.FILES: - doc_ace.arquivo = request.FILES['arquivo'] - doc = DocumentoAdministrativo.objects.get( - id=kwargs['pk']) - doc_ace.documento = doc - doc_ace.save() - return self.form_valid(form) - else: - return self.form_invalid(form) + def get_queryset(self): + qs = super(MasterDetailCrud.ListView, self).get_queryset() + kwargs = {self.crud.parent_field: self.kwargs['pk']} + return qs.filter(**kwargs).order_by('-data_tramitacao', '-id') - def get_success_url(self): - pk = self.kwargs['pk'] - return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk}) + class DetailView(DocumentoAdministrativoMixin, + MasterDetailCrud.DetailView): + pass -class TramitacaoAdmCrud(MasterDetailCrud): - model = TramitacaoAdministrativo +class DocumentoAcessorioAdministrativoCrud(MasterDetailCrud): + model = DocumentoAcessorioAdministrativo parent_field = 'documento' help_path = '' class BaseMixin(MasterDetailCrud.BaseMixin): - list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', - 'unidade_tramitacao_destino', 'status'] + list_field_names = ['nome', 'tipo', + 'data', 'autor', + 'assunto'] class CreateView(MasterDetailCrud.CreateView): - form_class = TramitacaoAdmForm + form_class = DocumentoAcessorioAdministrativoForm class UpdateView(MasterDetailCrud.UpdateView): - form_class = TramitacaoAdmEditForm + form_class = DocumentoAcessorioAdministrativoForm class ListView(DocumentoAdministrativoMixin, MasterDetailCrud.ListView): def get_queryset(self): qs = super(MasterDetailCrud.ListView, self).get_queryset() kwargs = {self.crud.parent_field: self.kwargs['pk']} - return qs.filter(**kwargs).order_by('-data_tramitacao', '-id') + return qs.filter(**kwargs).order_by('-data', '-id') class DetailView(DocumentoAdministrativoMixin, MasterDetailCrud.DetailView): diff --git a/sapl/templates/protocoloadm/layouts.yaml b/sapl/templates/protocoloadm/layouts.yaml index 8b6c935d0..fad574562 100644 --- a/sapl/templates/protocoloadm/layouts.yaml +++ b/sapl/templates/protocoloadm/layouts.yaml @@ -16,9 +16,8 @@ DocumentoAdministrativo: DocumentoAcessorioAdministrativo: {% trans 'Documento Acessório' %}: - - documento tipo + - tipo autor - nome data - - autor - arquivo - assunto diff --git a/sapl/templates/protocoloadm/subnav.yaml b/sapl/templates/protocoloadm/subnav.yaml index 22857647b..ff4feb42e 100644 --- a/sapl/templates/protocoloadm/subnav.yaml +++ b/sapl/templates/protocoloadm/subnav.yaml @@ -3,3 +3,5 @@ url: documentoadministrativo_detail - title: {% trans 'Tramitação' %} url: tramitacaoadministrativo_list +- title: {% trans 'Documento Acessório' %} + url: documentoacessorioadministrativo_list