Browse Source

Ajst js de psq autor e insere drf base para combos

pull/1356/head
LeandroRoberto 8 years ago
parent
commit
3ee0521196
  1. 11
      sapl/api/forms.py
  2. 4
      sapl/api/urls.py
  3. 10
      sapl/api/views.py
  4. 5
      sapl/settings.py
  5. 7
      sapl/static/js/app.js

11
sapl/api/forms.py

@ -117,3 +117,14 @@ class AutorSearchForFieldFilterSet(AutorChoiceFilterSet):
v = '1' if v == 'True' else '0' v = '1' if v == 'True' else '0'
params[key] = v params[key] = v
return queryset.filter(**params).distinct('nome').order_by('nome') return queryset.filter(**params).distinct('nome').order_by('nome')
class AutoresPossiveisFilterSet(FilterSet):
tipo = MethodFilter()
class Meta:
model = Autor
fields = ['tipo', ]
def filter_tipo(self, queryset, value):
return queryset

4
sapl/api/urls.py

@ -18,9 +18,9 @@ urlpatterns_router = router.urls
urlpatterns_api = [ urlpatterns_api = [
url(r'^autores-provaveis', url(r'^autor/provaveis',
AutoresProvaveisListView.as_view(), name='autores_provaveis_list'), AutoresProvaveisListView.as_view(), name='autores_provaveis_list'),
url(r'^autores-possiveis', url(r'^autor/possiveis',
AutoresPossiveisListView.as_view(), name='autores_possiveis_list'), AutoresPossiveisListView.as_view(), name='autores_possiveis_list'),
url(r'^autor', AutorListView.as_view(), name='autor_list'), url(r'^autor', AutorListView.as_view(), name='autor_list'),

10
sapl/api/views.py

@ -9,7 +9,8 @@ from rest_framework.permissions import (AllowAny, IsAuthenticated,
IsAuthenticatedOrReadOnly) IsAuthenticatedOrReadOnly)
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from sapl.api.forms import AutorChoiceFilterSet, AutorSearchForFieldFilterSet from sapl.api.forms import AutorChoiceFilterSet, AutorSearchForFieldFilterSet,\
AutoresPossiveisFilterSet
from sapl.api.serializers import (AutorChoiceSerializer, AutorSerializer, from sapl.api.serializers import (AutorChoiceSerializer, AutorSerializer,
ChoiceSerializer, ChoiceSerializer,
MateriaLegislativaSerializer, MateriaLegislativaSerializer,
@ -70,7 +71,7 @@ class AutorListView(ListAPIView):
o django-filter é desativado e a busca é feita o django-filter é desativado e a busca é feita
no model do ContentType associado ao tipo. no model do ContentType associado ao tipo.
- q_0 / q_1 - q_0 faz o código ignorar "q"... - q_0 / q_1 - q_0 é opcional e quando usado, faz o código ignorar "q"...
q_0 -> campos lookup a serem filtrados em qualquer Model q_0 -> campos lookup a serem filtrados em qualquer Model
que implemente SaplGenericRelation que implemente SaplGenericRelation
@ -150,6 +151,7 @@ class AutorListView(ListAPIView):
return tr return tr
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if self.tr == AutorListView.TR_AUTOR_SERIALIZER: if self.tr == AutorListView.TR_AUTOR_SERIALIZER:
self.serializer_class = AutorSerializer self.serializer_class = AutorSerializer
self.permission_classes = (IsAuthenticated,) self.permission_classes = (IsAuthenticated,)
@ -246,9 +248,9 @@ class AutoresPossiveisListView(ListAPIView):
queryset = Autor.objects.all() queryset = Autor.objects.all()
model = Autor model = Autor
filter_class = AutorChoiceFilterSet filter_class = AutoresPossiveisFilterSet
filter_backends = (DjangoFilterBackend, ) filter_backends = (DjangoFilterBackend, )
serializer_class = ChoiceSerializer serializer_class = AutorChoiceSerializer
class MateriaLegislativaViewSet(ListModelMixin, class MateriaLegislativaViewSet(ListModelMixin,

5
sapl/settings.py

@ -22,6 +22,7 @@ from unipath import Path
from .temp_suppress_crispy_form_warnings import \ from .temp_suppress_crispy_form_warnings import \
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
BASE_DIR = Path(__file__).ancestor(1) BASE_DIR = Path(__file__).ancestor(1)
PROJECT_DIR = Path(__file__).ancestor(2) PROJECT_DIR = Path(__file__).ancestor(2)
@ -101,7 +102,7 @@ if SOLR_URL:
HAYSTACK_CONNECTIONS = { HAYSTACK_CONNECTIONS = {
'default': { 'default': {
'ENGINE': SEARCH_BACKEND, 'ENGINE': SEARCH_BACKEND,
SEARCH_URL[0] : SEARCH_URL[1] SEARCH_URL[0]: SEARCH_URL[1]
}, },
} }
@ -200,7 +201,7 @@ MAX_IMAGE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
# https://docs.djangoproject.com/en/1.8/topics/i18n/ # https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'pt-br' LANGUAGE_CODE = 'pt-br'
LANGUAGES = ( LANGUAGES = (
('pt-br','Português'), ('pt-br', 'Português'),
) )
TIME_ZONE = 'America/Sao_Paulo' TIME_ZONE = 'America/Sao_Paulo'

7
sapl/static/js/app.js

@ -58,7 +58,7 @@ function autorModal() {
autoOpen: false, autoOpen: false,
modal: true, modal: true,
width: 500, width: 500,
height: 300, height: 340,
show: { show: {
effect: "blind", effect: "blind",
duration: 500}, duration: 500},
@ -111,11 +111,12 @@ function autorModal() {
select.append($("<option>").attr('value', item.value).text(item.text)); select.append($("<option>").attr('value', item.value).text(item.text));
}); });
$("#div-resultado").append("<br/>").append(select); $("#div-resultado").append("<br/>").append(select);
$("#selecionar").removeAttr("hidden", "hidden"); $("#selecionar").removeAttr("hidden", "hidden");
if (data.pagination.total_pages > 1)
$("#div-resultado").prepend('<span><br/>Mostrando 10 primeiros autores relativos a sua busca.<br/></span>');
$("#selecionar").click(function() { $("#selecionar").click(function() {
res = $("#resultados option:selected"); res = $("#resultados option:selected");
id = res.val(); id = res.val();

Loading…
Cancel
Save