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'
params[key] = v
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 = [
url(r'^autores-provaveis',
url(r'^autor/provaveis',
AutoresProvaveisListView.as_view(), name='autores_provaveis_list'),
url(r'^autores-possiveis',
url(r'^autor/possiveis',
AutoresPossiveisListView.as_view(), name='autores_possiveis_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)
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,
ChoiceSerializer,
MateriaLegislativaSerializer,
@ -70,7 +71,7 @@ class AutorListView(ListAPIView):
o django-filter é desativado e a busca é feita
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
que implemente SaplGenericRelation
@ -150,6 +151,7 @@ class AutorListView(ListAPIView):
return tr
def get(self, request, *args, **kwargs):
if self.tr == AutorListView.TR_AUTOR_SERIALIZER:
self.serializer_class = AutorSerializer
self.permission_classes = (IsAuthenticated,)
@ -246,9 +248,9 @@ class AutoresPossiveisListView(ListAPIView):
queryset = Autor.objects.all()
model = Autor
filter_class = AutorChoiceFilterSet
filter_class = AutoresPossiveisFilterSet
filter_backends = (DjangoFilterBackend, )
serializer_class = ChoiceSerializer
serializer_class = AutorChoiceSerializer
class MateriaLegislativaViewSet(ListModelMixin,

5
sapl/settings.py

@ -22,6 +22,7 @@ from unipath import Path
from .temp_suppress_crispy_form_warnings import \
SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
BASE_DIR = Path(__file__).ancestor(1)
PROJECT_DIR = Path(__file__).ancestor(2)
@ -101,7 +102,7 @@ if SOLR_URL:
HAYSTACK_CONNECTIONS = {
'default': {
'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/
LANGUAGE_CODE = 'pt-br'
LANGUAGES = (
('pt-br','Português'),
('pt-br', 'Português'),
)
TIME_ZONE = 'America/Sao_Paulo'

7
sapl/static/js/app.js

@ -58,7 +58,7 @@ function autorModal() {
autoOpen: false,
modal: true,
width: 500,
height: 300,
height: 340,
show: {
effect: "blind",
duration: 500},
@ -111,11 +111,12 @@ function autorModal() {
select.append($("<option>").attr('value', item.value).text(item.text));
});
$("#div-resultado").append("<br/>").append(select);
$("#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() {
res = $("#resultados option:selected");
id = res.val();

Loading…
Cancel
Save