Browse Source

3177 - Adiciona Pesquisa de Autor (#3196)

* Adiciona pesquisa de autor

* Corrige nome do campo para pesquisa
pull/3214/head
Vinícius Cantuária 5 years ago
committed by GitHub
parent
commit
6edbedecae
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      sapl/base/forms.py
  2. 4
      sapl/base/urls.py
  3. 54
      sapl/base/views.py
  4. 14
      sapl/templates/base/autor_detail.html
  5. 51
      sapl/templates/base/autor_filter.html
  6. 7
      sapl/templates/menu_tabelas_auxiliares.yaml

20
sapl/base/forms.py

@ -770,6 +770,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'),

4
sapl/base/urls.py

@ -8,7 +8,8 @@ from django.contrib.auth.views import (password_reset, password_reset_complete,
password_reset_done)
from django.views.generic.base import RedirectView, TemplateView
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
@ -90,6 +91,7 @@ recuperar_senha = [
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<topic>\w+)$',
HelpTopicView.as_view(), name='help_topic'),

54
sapl/base/views.py

@ -41,7 +41,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 (Anexada, Autoria, DocumentoAcessorio,
@ -295,6 +295,58 @@ class AutorCrud(CrudAux):
return url_reverse
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'

14
sapl/templates/base/autor_detail.html

@ -0,0 +1,14 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags staticfiles %}
{% block sub_actions %}
<div class="actions btn-group btn-group-sm" role="group">
<a href="{% url 'sapl.base:pesquisar_autor' %}" class="btn btn-outline-primary">
{% blocktrans with verbose_name=view.verbose_name %} Pesquisar {{ verbose_name }} {% endblocktrans %}
</a>
<a href="{{ view.create_url }}" class="btn btn-outline-primary">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
</div>
{% endblock sub_actions %}

51
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 %}
<div class="actions btn-group float-right btn-group-sm" role="group">
<a href="{% url 'sapl.base:pesquisar_autor' %}" class="btn btn-outline-primary">{% trans 'Fazer nova pesquisa' %}</a>
{% if not request.user.is_anonymous %}
<a href="{% url 'sapl.base:autor_create' %}"class="btn btn-outline-primary">Cadastrar Autor</a>
{% endif %}
</div>
<br>
{% if numero_res > 0 %}
{% if numero_res == 1 %}
<p>Foi encontrado {{ numero_res }} resultado</p>
{% else %}
<p>Foram encontrados {{ numero_res }} resultados</p>
{% endif %}
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Tipo do Autor</th>
<th>Nome do Autor</th>
<th>Usuário</th>
</tr>
</thead>
<tbody>
{% for autor in page_obj %}
<tr>
<td>{{ autor.tipo }}</td>
<td>
<a href="{% url 'sapl.base:autor_detail' autor.pk %}">
{% if autor.nome %} {{ autor.nome }} {% else %} - {% endif %}
</a>
</td>
<td>{% if autor.user %} {{ autor.user }} {% else %} - {% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<font size="4"><p align="center">{{ NO_ENTRIES_MSG }}</p></font>
{% endif %}
{% endif %}
<br/>
{% include 'paginacao.html'%}
<br /><br /><br />
{% endblock base_content %}

7
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

Loading…
Cancel
Save