diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index 7feb3b3c3..85153b846 100644 --- a/sapl/norma/forms.py +++ b/sapl/norma/forms.py @@ -40,6 +40,31 @@ ORDENACAO_CHOICES = [('', '---------'), ('data,tipo,ano,numero', _('Data/Tipo/Ano/Número'))] +class AssuntoNormaFilterSet(django_filters.FilterSet): + assunto = django_filters.CharFilter(label=_("Assunto"), + method='multifield_filter') + + class Meta: + model = AssuntoNorma + fields = ["assunto"] + + def multifield_filter(self, queryset, name, value): + return queryset.filter(Q(assunto__icontains=value) | Q(descricao__icontains=value)) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + row0 = to_row([("assunto", 12)]) + + self.form.helper = SaplFormHelper() + self.form.helper.form_method = "GET" + self.form.helper.layout = Layout( + Fieldset( + _("Pesquisa de Assunto de Norma Jurídica"), + row0, form_actions(label="Pesquisar")) + ) + + class NormaFilterSet(django_filters.FilterSet): ano = django_filters.ChoiceFilter(required=False, diff --git a/sapl/norma/urls.py b/sapl/norma/urls.py index 800707915..3a941e0b3 100644 --- a/sapl/norma/urls.py +++ b/sapl/norma/urls.py @@ -1,9 +1,11 @@ from django.conf.urls import include, url -from sapl.norma.views import (AnexoNormaJuridicaCrud,AssuntoNormaCrud, NormaCrud, NormaPesquisaView, +from sapl.norma.views import (AnexoNormaJuridicaCrud, AssuntoNormaCrud, + NormaCrud, NormaPesquisaView, NormaRelacionadaCrud, NormaTaView, TipoNormaCrud, TipoVinculoNormaJuridicaCrud, recuperar_norma, - recuperar_numero_norma, AutoriaNormaCrud) + recuperar_numero_norma, AutoriaNormaCrud, + PesquisarAssuntoNormaView) from .apps import AppConfig @@ -19,7 +21,13 @@ urlpatterns = [ # Integração com Compilação url(r'^norma/(?P[0-9]+)/ta$', NormaTaView.as_view(), name='norma_ta'), url(r'^sistema/norma/tipo/', include(TipoNormaCrud.get_urls())), + url(r'^sistema/norma/assunto/', include(AssuntoNormaCrud.get_urls())), + url( + r'^sistema/norma/pesquisar-assunto-norma/', + PesquisarAssuntoNormaView.as_view(), name="pesquisar_assuntonorma" + ), + url(r'^sistema/norma/vinculo/', include( TipoVinculoNormaJuridicaCrud.get_urls())), diff --git a/sapl/norma/views.py b/sapl/norma/views.py index dfb670f74..1281f9d76 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -28,14 +28,13 @@ from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, from sapl.utils import show_results_filter_set, get_client_ip from .forms import (AnexoNormaJuridicaForm, NormaFilterSet, NormaJuridicaForm, - NormaPesquisaSimplesForm, NormaRelacionadaForm, AutoriaNormaForm) + NormaPesquisaSimplesForm, NormaRelacionadaForm, + AutoriaNormaForm, AssuntoNormaFilterSet) from .models import (AnexoNormaJuridica, AssuntoNorma, NormaJuridica, NormaRelacionada, TipoNormaJuridica, TipoVinculoNormaJuridica, AutoriaNorma, NormaEstatisticas) # LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') -AssuntoNormaCrud = CrudAux.build(AssuntoNorma, 'assunto_norma_juridica', - list_field_names=['assunto', 'descricao']) TipoNormaCrud = CrudAux.build( @@ -46,6 +45,75 @@ TipoVinculoNormaJuridicaCrud = CrudAux.build( list_field_names=['sigla', 'descricao_ativa', 'descricao_passiva', 'revoga_integralmente']) +class AssuntoNormaCrud(CrudAux): + model = AssuntoNorma + + class BaseMixin(CrudAux.BaseMixin): + list_field_names = ["assunto", "descricao"] + + class DeleteView(CrudAux.DeleteView): + def get_success_url(self): + return reverse('sapl.norma:pesquisar_assuntonorma') + + +class PesquisarAssuntoNormaView(FilterView): + model = AssuntoNorma + filterset_class = AssuntoNormaFilterSet + paginate_by = 10 + + def get_filterset_kwargs(self, filterset_class): + super(PesquisarAssuntoNormaView, self).get_filterset_kwargs( + filterset_class + ) + + return ({ + "data": self.request.GET or None, + "queryset": self.get_queryset().order_by("assunto").distinct() + }) + + def get_context_data(self, **kwargs): + context = super(PesquisarAssuntoNormaView, self).get_context_data( + **kwargs + ) + + paginator = context["paginator"] + page_obj = context["page_obj"] + + context.update({ + "page_range": make_pagination( + page_obj.number, paginator.num_pages + ), + "NO_ENTRIES_MSG": "Nenhum assunto de norma jurídica encontrado!", + "title": _("Assunto de Norma Jurídica") + }) + + return context + + def get(self, request, *args, **kwargs): + super(PesquisarAssuntoNormaView, self).get(request) + + data = self.filterset.data + + url = '' + + if data: + url = '&' + str(self.request.META["QUERY_STRING"]) + if url.startswith("&page"): + ponto_comeco = url.find("assunto=") - 1 + url = url[ponto_comeco:] + + context = self.get_context_data( + filter=self.filterset, object_list=self.object_list, + filter_url=url, numero_res=len(self.object_list) + ) + + context["show_results"] = show_results_filter_set( + self.request.GET.copy() + ) + + return self.render_to_response(context) + + class NormaRelacionadaCrud(MasterDetailCrud): model = NormaRelacionada parent_field = 'norma_principal' diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index 8bddd0f29..9e8f0e454 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -140,12 +140,15 @@ - title: {% trans 'Tipo de Norma Jurídica' %} url: sapl.norma:tiponormajuridica_list css_class: btn btn-link - - title: {% trans 'Assunto de Norma Jurídica' %} - url: sapl.norma:assuntonorma_list - css_class: btn btn-link - title: {% trans 'Tipo de Vínculo' %} url: sapl.norma:tipovinculonormajuridica_list css_class: btn btn-link + - title: {% trans 'Pesquisar Assunto de Norma Jurídica' %} + url: sapl.norma:pesquisar_assuntonorma + css_class: btn btn-link + - title: {% trans 'Adicionar Assunto de Norma Jurídica' %} + url: sapl.norma:assuntonorma_create + css_class: btn btn-link - title: {% trans 'Módulo Textos Articulados' %} css_class: head_title children: diff --git a/sapl/templates/norma/assuntonorma_detail.html b/sapl/templates/norma/assuntonorma_detail.html new file mode 100644 index 000000000..317264305 --- /dev/null +++ b/sapl/templates/norma/assuntonorma_detail.html @@ -0,0 +1,34 @@ +{% extends "crud/detail.html" %} +{% load i18n %} +{% load crispy_forms_tags cropping %} + +{% block actions %} +
+ + Pesquisar Assunto de Norma Jurídica + + + Adicionar Assunto de Norma Jurídica + +
+
+ + Editar + + + Excluir + +
+{% endblock actions %} diff --git a/sapl/templates/norma/assuntonorma_filter.html b/sapl/templates/norma/assuntonorma_filter.html new file mode 100644 index 000000000..3b8599d8a --- /dev/null +++ b/sapl/templates/norma/assuntonorma_filter.html @@ -0,0 +1,54 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags staticfiles %} + +{% block base_content %} + {% if not show_results %} + {% crispy filter.form %} + {% else %} +
+ + {% trans "Fazer nova pesquisa" %} + + {% if not request.user.is_anonymous %} + + Cadastrar Assunto de Norma Jurídica + + {% endif %} +
+
+ {% if numero_res > 0 %} + {% if numero_res == 1 %} +

Foi encontrado {{ numero_res }} resultado.

+ {% else %} +

Foram encontrados {{ numero_res }} resultados.

+ {% endif %} + + + + {% for assunto_norma in page_obj %} + + + + + {% endfor %} + +
AssuntoDescrição
+ + {{ assunto_norma.assunto }} + + {{ assunto_norma.descricao }}
+ {% else %} +

{{ NO_ENTRIES_MSG }}

+ {% endif %} + {% endif %} +
+ {% include "paginacao.html" %} +


+{% endblock base_content %}