From 8a1c5660027f8ce66d7989c99afdc914899408c7 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Thu, 27 Oct 2016 20:10:38 -0200 Subject: [PATCH] Restaura funcionalidades e alguns ajt em protocolo --- sapl/protocoloadm/forms.py | 11 ++-- sapl/protocoloadm/urls.py | 43 ++++++++------- sapl/protocoloadm/views.py | 52 ++++++++----------- sapl/rules/map_rules.py | 3 +- sapl/templates/crud/detail.html | 44 ++++++++-------- .../protocoloadm/anular_protocoloadm.html | 12 ++++- sapl/templates/protocoloadm/comprovante.html | 4 -- .../protocoloadm/protocolar_documento.html | 11 +++- .../protocoloadm/protocolar_materia.html | 10 +++- .../protocoloadm/protocolo_filter.html | 36 ++++++++----- .../protocoloadm/protocolo_mostrar.html | 6 +-- .../protocoloadm/protocoloadm_detail.html | 14 ++--- 12 files changed, 139 insertions(+), 107 deletions(-) diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index 549cdc498..de17af830 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -1,6 +1,5 @@ from datetime import datetime -import django_filters from crispy_forms.bootstrap import InlineRadios from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Fieldset, Layout, Submit @@ -9,6 +8,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ +import django_filters from sapl.base.models import Autor from sapl.crispy_layout_mixin import form_actions, to_row @@ -20,6 +20,7 @@ from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, TipoDocumentoAdministrativo, TramitacaoAdministrativo) + TIPOS_PROTOCOLO = [('0', 'Enviado'), ('1', 'Recebido'), ('', 'Ambos')] NATUREZA_PROCESSO = [('', 'Ambos'), @@ -131,7 +132,7 @@ class ProtocoloFilterSet(django_filters.FilterSet): self.form.helper = FormHelper() self.form.helper.form_method = 'GET' self.form.helper.layout = Layout( - Fieldset(_('Pesquisar Protocolo'), + Fieldset('', row1, row2, row3, HTML(autor_label), @@ -313,7 +314,7 @@ class ProtocoloDocumentForm(ModelForm): empty_label='Selecione', ) - num_paginas = forms.CharField(label=_('Núm. Páginas'), required=True) + numero_paginas = forms.CharField(label=_('Núm. Páginas'), required=True) assunto = forms.CharField( widget=forms.Textarea, label='Assunto', required=True) @@ -327,7 +328,7 @@ class ProtocoloDocumentForm(ModelForm): model = Protocolo fields = ['tipo_protocolo', 'tipo_documento', - 'num_paginas', + 'numero_paginas', 'assunto', 'interessado', 'observacao', @@ -339,7 +340,7 @@ class ProtocoloDocumentForm(ModelForm): [(InlineRadios('tipo_protocolo'), 12)]) row2 = to_row( [('tipo_documento', 6), - ('num_paginas', 6)]) + ('numero_paginas', 6)]) row3 = to_row( [('assunto', 12)]) row4 = to_row( diff --git a/sapl/protocoloadm/urls.py b/sapl/protocoloadm/urls.py index 7b2a1ac69..07c89029e 100644 --- a/sapl/protocoloadm/urls.py +++ b/sapl/protocoloadm/urls.py @@ -9,9 +9,7 @@ from sapl.protocoloadm.views import (AnularProtocoloAdmView, DocumentoAcessorioAdministrativoView, DocumentoAdministrativoCrud, PesquisarDocumentoAdministrativoView, - ProtocoloDocumentoCrud, ProtocoloDocumentoView, ProtocoloListView, - ProtocoloMateriaCrud, ProtocoloMateriaView, ProtocoloMostrarView, ProtocoloPesquisaView, @@ -42,31 +40,38 @@ urlpatterns_documento_administrativo = [ ] urlpatterns_protocolo = [ - url(r'^protocoloadm/protocolo-doc/', - include(ProtocoloDocumentoCrud.get_urls())), - url(r'^protocoloadm/protocolo-mat/', - include(ProtocoloMateriaCrud.get_urls()), name='protocolomat'), - url(r'^protocoloadm/protocolo$', + + # url(r'^protocoloadm/protocolo-doc/', + # include(ProtocoloDocumentoCrud.get_urls())), + # url(r'^protocoloadm/protocolo-mat/', + # include(ProtocoloMateriaCrud.get_urls()), name='protocolomat'), + # url(r'^protocoloadm/protocolo-list$', + # ProtocoloListView.as_view(), name='protocolo_list'), + + url(r'^protocoloadm/$', ProtocoloPesquisaView.as_view(), name='protocolo'), - url(r'^protocoloadm/protocolo-list$', - ProtocoloListView.as_view(), name='protocolo_list'), - url(r'^protocoloadm/anular-protocolo', - AnularProtocoloAdmView.as_view(), name='anular_protocolo'), + url(r'^protocoloadm/protocolar-doc', ProtocoloDocumentoView.as_view(), name='protocolar_doc'), + + + url(r'^protocoloadm/(?P\d+)/protocolo-mostrar$', + ProtocoloMostrarView.as_view(), name='protocolo_mostrar'), + + + + + + url(r'^protocoloadm/anular-protocolo', + AnularProtocoloAdmView.as_view(), name='anular_protocolo'), url(r'^protocoloadm/protocolar-mat', ProtocoloMateriaView.as_view(), name='protocolar_mat'), - # FIXME estas urls com pk e ano não fazem sentido - # se vai buscar por pk não precisa de nenhuma outra informação - # mas veja, apesar de chamar de pk aqui nas urls - # usou-se dentro da view como paramentro para ano. - url(r'^protocoloadm/(?P\d+)/(?P\d+)/protocolo-mostrar$', - ProtocoloMostrarView.as_view(), name='protocolo_mostrar'), - url(r'^protocoloadm/(?P\d+)/(?P\d+)/comprovante$', + url(r'^protocoloadm/(?P\d+)/comprovante$', ComprovanteProtocoloView.as_view(), name='comprovante_protocolo'), - url(r'^protocoloadm/(?P\d+)/(?P\d+)/criar-documento$', + url(r'^protocoloadm/(?P\d+)/criar-documento$', CriarDocumentoProtocolo.as_view(), name='criar_documento'), + ] urlpatterns_sistema = [ diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 961ff01ab..9245de6ef 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -31,9 +31,9 @@ TipoDocumentoAdministrativoCrud = CrudAux.build( TipoDocumentoAdministrativo, '') -ProtocoloDocumentoCrud = Crud.build(Protocolo, '') +#ProtocoloDocumentoCrud = Crud.build(Protocolo, '') # FIXME precisa de uma chave diferente para o layout -ProtocoloMateriaCrud = Crud.build(Protocolo, '') +#ProtocoloMateriaCrud = Crud.build(Protocolo, '') DocumentoAcessorioAdministrativoCrud = Crud.build( @@ -109,6 +109,8 @@ class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView): context['page_range'] = make_pagination( page_obj.number, paginator.num_pages) + context['title'] = _('Pesquisa de Protocolos') + return context def get(self, request, *args, **kwargs): @@ -166,7 +168,7 @@ class AnularProtocoloAdmView(PermissionRequiredMixin, CreateView): template_name = 'protocoloadm/anular_protocoloadm.html' form_class = AnularProcoloAdmForm form_valid_message = _('Protocolo anulado com sucesso!') - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.action_anular_protocolo', ) def get_success_url(self): return reverse('sapl.protocoloadm:protocolo') @@ -195,10 +197,11 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, template_name = "protocoloadm/protocolar_documento.html" form_class = ProtocoloDocumentForm form_valid_message = _('Protocolo cadastrado com sucesso!') - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.add_protocolo', ) def get_success_url(self): - return reverse('sapl.protocoloadm:protocolo') + return reverse('sapl.protocoloadm:protocolo_mostrar', + kwargs={'pk': self.object.id}) def form_valid(self, form): f = form.save(commit=False) @@ -231,31 +234,28 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, f.assunto_ementa = self.request.POST['assunto'] f.save() + self.object = f return redirect(self.get_success_url()) class CriarDocumentoProtocolo(PermissionRequiredMixin, CreateView): template_name = "protocoloadm/criar_documento.html" form_class = DocumentoAdministrativoForm - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.add_documentoadministrativo',) def get_initial(self): - numero = self.kwargs['pk'] - ano = self.kwargs['ano'] - protocolo = Protocolo.objects.get(ano=ano, numero=numero) + protocolo = Protocolo.objects.get(pk=self.kwargs['pk']) return self.criar_documento(protocolo) def get_success_url(self): return reverse('sapl.protocoloadm:protocolo_mostrar', - kwargs={'pk': self.kwargs['pk'], - 'ano': self.kwargs['ano']}) + kwargs={'pk': self.kwargs['pk']}) def criar_documento(self, protocolo): - numero = Protocolo.objects.filter( - tipo_documento=protocolo.tipo_documento, - ano=protocolo.ano, - anulado=False).aggregate(Max('numero')) + numero_max = DocumentoAdministrativo.objects.filter( + tipo=protocolo.tipo_documento + ).aggregate(Max('numero'))['numero__max'] doc = {} doc['tipo'] = protocolo.tipo_documento @@ -264,24 +264,18 @@ class CriarDocumentoProtocolo(PermissionRequiredMixin, CreateView): doc['numero_protocolo'] = protocolo.numero doc['assunto'] = protocolo.assunto_ementa doc['interessado'] = protocolo.interessado - doc['numero'] = numero['numero__max'] - if doc['numero'] is None: - doc['numero'] = 1 - else: - doc['numero'] = doc['numero'] + 1 + doc['numero'] = numero_max + 1 if numero_max else 1 return doc class ProtocoloMostrarView(PermissionRequiredMixin, TemplateView): template_name = "protocoloadm/protocolo_mostrar.html" - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.detail_protocolo', ) def get_context_data(self, **kwargs): context = super(ProtocoloMostrarView, self).get_context_data(**kwargs) - numero = self.kwargs['pk'] - ano = self.kwargs['ano'] - protocolo = Protocolo.objects.get(ano=ano, numero=numero) + protocolo = Protocolo.objects.get(pk=self.kwargs['pk']) context['protocolo'] = protocolo return context @@ -289,16 +283,14 @@ class ProtocoloMostrarView(PermissionRequiredMixin, TemplateView): class ComprovanteProtocoloView(PermissionRequiredMixin, TemplateView): template_name = "protocoloadm/comprovante.html" - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.detail_protocolo', ) def get_context_data(self, **kwargs): context = super(ComprovanteProtocoloView, self).get_context_data( **kwargs) - numero = self.kwargs['pk'] - ano = self.kwargs['ano'] - protocolo = Protocolo.objects.get(ano=ano, numero=numero) + protocolo = Protocolo.objects.get(pk=self.kwargs['pk']) # numero is string, padd with zeros left via .zfill() - base64_data = create_barcode(numero.zfill(6)) + base64_data = create_barcode(str(protocolo.numero).zfill(6)) barcode = 'data:image/png;base64,{0}'.format(base64_data) autenticacao = _("** NULO **") @@ -320,7 +312,7 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView): template_name = "protocoloadm/protocolar_materia.html" form_class = ProtocoloMateriaForm form_valid_message = _('Matéria cadastrada com sucesso!') - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.add_protocolo',) def get_success_url(self): return reverse('sapl.protocoloadm:protocolo') diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index fcee49c86..f181ee99e 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -35,7 +35,8 @@ rules_group_protocolo = { 'rules': [ (protocoloadm.Protocolo, __base__ + [ 'action_anular_protocolo']), - (protocoloadm.DocumentoAdministrativo, __listdetailchange__), + (protocoloadm.DocumentoAdministrativo, + [RP_ADD] + __listdetailchange__), (protocoloadm.DocumentoAcessorioAdministrativo, __listdetailchange__), (materia.MateriaLegislativa, __listdetailchange__), diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 8d824b0f2..f88ba897d 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -41,30 +41,32 @@ {% endblock actions %} - {% block detail_content %} - {% for fieldset in view.layout_display %} -

{{ fieldset.legend }}

- {% for row in fieldset.rows %} -
- {% for column in row %} -
-
-

{{ column.verbose_name }}

-
- {% comment %}TODO Transformar os links em URLs diretamente no CRUD{% endcomment %} - {% if column.text|url %} - - {% else %} -
{{ column.text|safe }}
- {% endif %} +
+ {% block detail_content %} + {% for fieldset in view.layout_display %} +

{{ fieldset.legend }}

+ {% for row in fieldset.rows %} +
+ {% for column in row %} +
+
+

{{ column.verbose_name }}

+
+ {% comment %}TODO Transformar os links em URLs diretamente no CRUD{% endcomment %} + {% if column.text|url %} + + {% else %} +
{{ column.text|safe }}
+ {% endif %} +
-
- {% endfor %} -
+ {% endfor %} +
+ {% endfor %} {% endfor %} - {% endfor %} - {% endblock detail_content %} + {% endblock detail_content %} +
{% block table_content %}
diff --git a/sapl/templates/protocoloadm/anular_protocoloadm.html b/sapl/templates/protocoloadm/anular_protocoloadm.html index 97e772690..b936ed7ad 100644 --- a/sapl/templates/protocoloadm/anular_protocoloadm.html +++ b/sapl/templates/protocoloadm/anular_protocoloadm.html @@ -1,7 +1,17 @@ {% extends "protocoloadm/protocoloadm_detail.html" %} {% load i18n %} {% load crispy_forms_tags %} + + +{% block actions %} + + {{ block.super }} + +{% endblock %} + {% block detail_content %}
{{ message }}
{% crispy form %} -{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %} diff --git a/sapl/templates/protocoloadm/comprovante.html b/sapl/templates/protocoloadm/comprovante.html index de26eaf78..9fd9b8b32 100644 --- a/sapl/templates/protocoloadm/comprovante.html +++ b/sapl/templates/protocoloadm/comprovante.html @@ -83,9 +83,5 @@ Número Páginas {{ protocolo.numero_paginas }} - - Número Páginas - {{ protocolo.numero_paginas }} - {% endblock detail_content %} diff --git a/sapl/templates/protocoloadm/protocolar_documento.html b/sapl/templates/protocoloadm/protocolar_documento.html index 87259a900..9f2213128 100644 --- a/sapl/templates/protocoloadm/protocolar_documento.html +++ b/sapl/templates/protocoloadm/protocolar_documento.html @@ -2,6 +2,15 @@ {% load i18n %} {% load crispy_forms_tags %} + +{% block actions %} + + {{ block.super }} + +{% endblock %} + {% block detail_content %} {% crispy form %} -{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %} diff --git a/sapl/templates/protocoloadm/protocolar_materia.html b/sapl/templates/protocoloadm/protocolar_materia.html index 87259a900..744126f0d 100644 --- a/sapl/templates/protocoloadm/protocolar_materia.html +++ b/sapl/templates/protocoloadm/protocolar_materia.html @@ -2,6 +2,14 @@ {% load i18n %} {% load crispy_forms_tags %} +{% block actions %} + + {{ block.super }} + +{% endblock %} + {% block detail_content %} {% crispy form %} -{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %} diff --git a/sapl/templates/protocoloadm/protocolo_filter.html b/sapl/templates/protocoloadm/protocolo_filter.html index 19125ad95..a18ea7fb9 100644 --- a/sapl/templates/protocoloadm/protocolo_filter.html +++ b/sapl/templates/protocoloadm/protocolo_filter.html @@ -3,20 +3,25 @@ {% load crispy_forms_tags %} {% load static %} -{% block sections_nav %} {% endblock %} -{% block base_content %} -

Pesquisa de Protocolo

-

- {% if filter_url %} - - {% endif %} + {% block actions %} - {% if not filter_url %} - {% crispy filter.form %} - {% endif %} + {{ block.super }} + + {% if filter_url %} + + {% endif %} + + + {% endblock %} + + {% block detail_content %} +
+ {% if not filter_url %} + {% crispy filter.form %} + {% endif %} {% if filter_url %} @@ -33,7 +38,7 @@
Protocolo: - {{ p.numero|stringformat:'06d' }}/{{ p.ano }}  -   + {{ p.numero|stringformat:'06d' }}/{{ p.ano }}  -   Etiqueta Individual
Assunto: {{ p.assunto_ementa|default_if_none:"Não Informado"}}
Data Protocolo: {{ p.data|date:"d/m/Y"|default_if_none:"Não Informado" }} - Horário: {{ p.hora|date:"G:i:s" }}
@@ -50,4 +55,7 @@
{% include "paginacao.html" %} {% endif %} -{% endblock base_content %} +{% endblock detail_content %} + +{% block table_content %} +{% endblock table_content %} diff --git a/sapl/templates/protocoloadm/protocolo_mostrar.html b/sapl/templates/protocoloadm/protocolo_mostrar.html index 58882a39e..6a369b781 100644 --- a/sapl/templates/protocoloadm/protocolo_mostrar.html +++ b/sapl/templates/protocoloadm/protocolo_mostrar.html @@ -16,8 +16,8 @@
Documento Vinculado:
- Criar Documento + Criar Documento      - Comprovante + Comprovante -{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %} diff --git a/sapl/templates/protocoloadm/protocoloadm_detail.html b/sapl/templates/protocoloadm/protocoloadm_detail.html index 07ae81c47..dc91ac252 100644 --- a/sapl/templates/protocoloadm/protocoloadm_detail.html +++ b/sapl/templates/protocoloadm/protocoloadm_detail.html @@ -1,9 +1,9 @@ {% extends "crud/detail.html" %} {% load i18n %} -{% block actions %} - -{% endblock actions %} \ No newline at end of file +{% block editions %} + +{% endblock editions %}