diff --git a/sapl/base/forms.py b/sapl/base/forms.py index df3930f00..9a5f374b6 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -662,6 +662,26 @@ class AutorForm(ModelForm): return autor +class AutorFilterSet(django_filters.FilterSet): + nome = django_filters.CharFilter(label=_('Nome do Autor'), lookup_expr='icontains') + + class Meta: + model = Autor + fields = ['nome'] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + row0 = to_row([('nome', 12)]) + + self.form.helper = SaplFormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisa de Autor'), + row0, + form_actions(label='Pesquisar'))) + + class AutorFormForAdmin(AutorForm): status_user = forms.ChoiceField( label=_('Bloqueio do Usuário Existente'), diff --git a/sapl/base/urls.py b/sapl/base/urls.py index cd2e3ea1a..784428838 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -8,8 +8,10 @@ from django.contrib.auth.views import (password_reset, password_reset_complete, password_reset_done) from django.views.generic.base import RedirectView, TemplateView + from sapl import base -from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud, get_estatistica, DetailUsuarioView +from sapl.base.views import (AutorCrud, ConfirmarEmailView, TipoAutorCrud, + get_estatistica, DetailUsuarioView, PesquisarAutorView) from sapl.settings import EMAIL_SEND_USER, MEDIA_URL from .apps import AppConfig @@ -105,6 +107,7 @@ channels_url = [ urlpatterns = [ url(r'^sistema/autor/tipo/', include(TipoAutorCrud.get_urls())), url(r'^sistema/autor/', include(AutorCrud.get_urls())), + url(r'^sistema/autor/pesquisar-autor/', PesquisarAutorView.as_view(), name='pesquisar_autor'), url(r'^sistema/ajuda/(?P\w+)$', HelpTopicView.as_view(), name='help_topic'), diff --git a/sapl/base/views.py b/sapl/base/views.py index a6235e48b..30b3d7720 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -43,7 +43,7 @@ from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_ma from sapl import settings from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica from sapl.base.models import Autor, TipoAutor -from sapl.base.forms import AutorForm, AutorFormForAdmin, TipoAutorForm +from sapl.base.forms import AutorForm, AutorFormForAdmin, TipoAutorForm, AutorFilterSet from sapl.comissoes.models import Comissao, Reuniao from sapl.crud.base import CrudAux, make_pagination from sapl.materia.models import (Autoria, MateriaLegislativa, Proposicao, Anexada, @@ -328,7 +328,6 @@ class AutorCrud(CrudAux): return url_reverse - class DetailView(CrudAux.DetailView): def get_context_data(self, **kwargs): @@ -336,6 +335,59 @@ class AutorCrud(CrudAux): context['autor_user'] = AutorUser.objects.filter(autor=context['object']) return context + +class PesquisarAutorView(FilterView): + model = Autor + filterset_class = AutorFilterSet + paginate_by = 10 + + def get_filterset_kwargs(self, filterset_class): + super().get_filterset_kwargs(filterset_class) + + kwargs = {'data': self.request.GET or None} + + qs = self.get_queryset().order_by('nome').distinct() + + kwargs.update({ + 'queryset': qs, + }) + return kwargs + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + paginator = context['paginator'] + page_obj = context['page_obj'] + + context['page_range'] = make_pagination(page_obj.number, paginator.num_pages) + + context['NO_ENTRIES_MSG'] = 'Nenhum Autor encontrado!' + + context['title'] = _('Autores') + + return context + + def get(self, request, *args, **kwargs): + super().get(request) + + data = self.filterset.data + url = '' + if data: + url = "&" + str(self.request.META['QUERY_STRING']) + if url.startswith("&page"): + ponto_comeco = url.find('nome=') - 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 RelatoriosListView(TemplateView): template_name = 'base/relatorios_list.html' diff --git a/sapl/templates/base/autor_detail.html b/sapl/templates/base/autor_detail.html index 6e9994d99..007944c1d 100644 --- a/sapl/templates/base/autor_detail.html +++ b/sapl/templates/base/autor_detail.html @@ -1,10 +1,17 @@ {% extends "crud/detail.html" %} {% load i18n %} +{% load crispy_forms_tags staticfiles %} {% block sub_actions %} {{block.super}}
Vincular Usuário + + {% blocktrans with verbose_name=view.verbose_name %} Pesquisar {{ verbose_name }} {% endblocktrans %} + + + {% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %} +
{% endblock sub_actions %} @@ -59,4 +66,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/sapl/templates/base/autor_filter.html b/sapl/templates/base/autor_filter.html new file mode 100644 index 000000000..5e1a05542 --- /dev/null +++ b/sapl/templates/base/autor_filter.html @@ -0,0 +1,51 @@ +{% 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 Autor + {% endif %} +
+
+ {% if numero_res > 0 %} + {% if numero_res == 1 %} +

Foi encontrado {{ numero_res }} resultado

+ {% else %} +

Foram encontrados {{ numero_res }} resultados

+ {% endif %} + + + + + + + + + + {% for autor in page_obj %} + + + + + + {% endfor %} + +
Tipo do AutorNome do AutorUsuário
{{ autor.tipo }} + + {% if autor.nome %} {{ autor.nome }} {% else %} - {% endif %} + + {% if autor.user %} {{ autor.user }} {% else %} - {% endif %}
+ {% else %} +

{{ NO_ENTRIES_MSG }}

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


+{% endblock base_content %} diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index cba8c9761..36560e651 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -8,8 +8,11 @@ - title: {% trans 'Configurações da Aplicação' %} url: sapl.base:appconfig_list css_class: btn btn-link - - title: {% trans 'Autor' %} - url: sapl.base:autor_list + - title: {% trans 'Pesquisar Autor' %} + url: sapl.base:pesquisar_autor + css_class: btn btn-link + - title: {% trans 'Adicionar Autor' %} + url: sapl.base:autor_create css_class: btn btn-link - title: {% trans 'Tipo de Autor' %} url: sapl.base:tipoautor_list