From ecd48d55ca36754ddaa5102f33180881969e3714 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Thu, 3 Aug 2017 08:36:57 -0300 Subject: [PATCH] =?UTF-8?q?Desmembra=20buscas=20de=20/api/autor=20em=20vie?= =?UTF-8?q?ws=20espec=C3=ADficas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/api/forms.py | 1 - sapl/api/urls.py | 8 ++++- sapl/api/views.py | 47 ++++++++++++++--------------- sapl/templates/base/autor_form.html | 5 ++- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/sapl/api/forms.py b/sapl/api/forms.py index e4951c1e3..f36b7724f 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -51,7 +51,6 @@ class SaplGenericRelationSearchFilterSet(FilterSet): if q: queryset = queryset.filter(q).order_by(*order_by) - print(queryset.query) return queryset diff --git a/sapl/api/urls.py b/sapl/api/urls.py index bf9c16c51..7d146e4bb 100644 --- a/sapl/api/urls.py +++ b/sapl/api/urls.py @@ -3,7 +3,8 @@ from django.conf.urls import include, url from rest_framework.routers import DefaultRouter from sapl.api.views import (AutorListView, MateriaLegislativaViewSet, - ModelChoiceView, SessaoPlenariaViewSet) + ModelChoiceView, SessaoPlenariaViewSet, + AutoresPossiveisListView, AutoresProvaveisListView) from .apps import AppConfig @@ -17,6 +18,11 @@ urlpatterns_router = router.urls urlpatterns_api = [ + url(r'^autores-provaveis', + AutoresProvaveisListView.as_view(), name='autores_provaveis_list'), + url(r'^autores-possiveis', + AutoresPossiveisListView.as_view(), name='autores_possiveis_list'), + url(r'^autor', AutorListView.as_view(), name='autor_list'), url(r'^model/(?P\d+)/(?P\d*)$', diff --git a/sapl/api/views.py b/sapl/api/views.py index 7d89b28b0..507551808 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -57,14 +57,6 @@ class AutorListView(ListAPIView): de Autores feita pelo django-filter -> processo usado nas pesquisas, o mais usado. - = 2 -> para (value, text) usados geralmente - em combobox, radiobox, checkbox, etc com pesquisa básica - de Autores mas feito para Possíveis Autores armazenados - segundo o ContentType associado ao Tipo de Autor via - relacionamento genérico. - Busca feita sem django-filter processada no get_queryset - -> processo no cadastro de autores para seleção e busca - dos possíveis autores = 3 -> Devolve instancias da classe Autor filtradas pelo django-filter @@ -132,10 +124,8 @@ class AutorListView(ListAPIView): """ TR_AUTOR_CHOICE_SERIALIZER = 1 - TR_CHOICE_SERIALIZER = 2 TR_AUTOR_SERIALIZER = 3 - # FIXME aplicar permissão correta de usuário permission_classes = (IsAuthenticatedOrReadOnly,) queryset = Autor.objects.all() model = Autor @@ -152,7 +142,6 @@ class AutorListView(ListAPIView): assert tr in ( AutorListView.TR_AUTOR_CHOICE_SERIALIZER, - AutorListView.TR_CHOICE_SERIALIZER, AutorListView.TR_AUTOR_SERIALIZER), sapl_logger.info( _("Tipo do Resultado a ser fornecido não existe!")) except: @@ -161,16 +150,7 @@ class AutorListView(ListAPIView): return tr def get(self, request, *args, **kwargs): - """ - desativa o django-filter se a busca for por possiveis autores - parametro tr = TR_CHOICE_SERIALIZER - """ - if self.tr == AutorListView.TR_CHOICE_SERIALIZER: - self.filter_class = None - self.filter_backends = [] - self.serializer_class = ChoiceSerializer - - elif self.tr == AutorListView.TR_AUTOR_SERIALIZER: + if self.tr == AutorListView.TR_AUTOR_SERIALIZER: self.serializer_class = AutorSerializer self.permission_classes = (IsAuthenticated,) @@ -179,12 +159,20 @@ class AutorListView(ListAPIView): return ListAPIView.get(self, request, *args, **kwargs) + +class AutoresProvaveisListView(ListAPIView): + + permission_classes = (IsAuthenticatedOrReadOnly,) + queryset = Autor.objects.all() + model = Autor + + filter_class = None + filter_backends = [] + serializer_class = ChoiceSerializer + def get_queryset(self): queryset = ListAPIView.get_queryset(self) - if self.filter_backends: - return queryset - params = {'content_type__isnull': False} tipo = '' @@ -252,6 +240,17 @@ class AutorListView(ListAPIView): return r +class AutoresPossiveisListView(ListAPIView): + + permission_classes = (IsAuthenticatedOrReadOnly,) + queryset = Autor.objects.all() + model = Autor + + filter_class = AutorChoiceFilterSet + filter_backends = (DjangoFilterBackend, ) + serializer_class = ChoiceSerializer + + class MateriaLegislativaViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): diff --git a/sapl/templates/base/autor_form.html b/sapl/templates/base/autor_form.html index 62d835c85..ec7ddfe7e 100644 --- a/sapl/templates/base/autor_form.html +++ b/sapl/templates/base/autor_form.html @@ -28,12 +28,11 @@ $(document).ready(function(){ var update_search = function(pk, atualizar=true) { var q = $('#id_q').val(); - var url = '{% url 'sapl.api:autor_list'%}' + var url = '{% url 'sapl.api:autores_provaveis_list'%}' var formData = { 'q' : q, - 'tipo' : pk, - 'tr' : '2' // tipo_resultado = 2 - api fornecerá possíveis Autores + 'tipo' : pk } $.get(url, formData).done(function(data) { active('pesquisa');