From 55963883265c9165aa62a8bf62e030395eb7d80b Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Sat, 5 Jan 2019 04:40:44 -0200 Subject: [PATCH] =?UTF-8?q?altera=C3=A7=C3=B5es=20m=C3=ADnimas=20para=20ex?= =?UTF-8?q?ecutar=20manage=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/api/forms.py | 2 +- sapl/api/views.py | 5 +++-- sapl/settings.py | 7 ++++--- sapl/utils.py | 21 ++++++++++----------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sapl/api/forms.py b/sapl/api/forms.py index fecfbf598..0c8a1889f 100644 --- a/sapl/api/forms.py +++ b/sapl/api/forms.py @@ -6,8 +6,8 @@ from django.forms.widgets import MultiWidget, TextInput from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from django_filters.filters import CharFilter, ModelChoiceFilter, DateFilter +from django_filters.rest_framework.filterset import FilterSet from rest_framework import serializers -from rest_framework.filters import FilterSet from sapl.base.models import Autor, TipoAutor from sapl.parlamentares.models import Legislatura diff --git a/sapl/api/views.py b/sapl/api/views.py index b8cafc1dd..336bb23d7 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -1,9 +1,10 @@ import logging + from django.contrib.contenttypes.models import ContentType from django.db.models import Q from django.http import Http404 from django.utils.translation import ugettext_lazy as _ -from rest_framework.filters import DjangoFilterBackend +from django_filters.rest_framework.backends import DjangoFilterBackend from rest_framework.generics import ListAPIView from rest_framework.mixins import ListModelMixin, RetrieveModelMixin from rest_framework.permissions import (AllowAny, IsAuthenticated, @@ -175,7 +176,7 @@ class AutoresProvaveisListView(ListAPIView): serializer_class = ChoiceSerializer def get_queryset(self): - + params = {'content_type__isnull': False} username = self.request.user.username tipo = '' diff --git a/sapl/settings.py b/sapl/settings.py index 80bf18273..63f18e325 100755 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -90,6 +90,7 @@ INSTALLED_APPS = ( 'haystack', 'sass_processor', 'rest_framework', + 'django_filters', 'reversion', 'reversion_compare', 'whoosh', @@ -110,7 +111,7 @@ SOLR_URL = config('SOLR_URL', cast=str, default='http://localhost:8983') SOLR_COLLECTION = config('SOLR_COLLECTION', cast=str, default='sapl') if USE_SOLR: - HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' #enable auto-index + HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' # enable auto-index SEARCH_BACKEND = 'haystack.backends.solr_backend.SolrEngine' SEARCH_URL = ('URL', '{}/solr/{}'.format(SOLR_URL, SOLR_COLLECTION)) @@ -118,7 +119,7 @@ if USE_SOLR: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': SEARCH_BACKEND, - SEARCH_URL[0]: SEARCH_URL[1], + SEARCH_URL[0]: SEARCH_URL[1], 'BATCH_SIZE': 1000, 'TIMEOUT': 60, }, @@ -166,7 +167,7 @@ REST_FRAMEWORK = { "DEFAULT_PAGINATION_CLASS": "sapl.api.pagination.StandardPagination", "DEFAULT_FILTER_BACKENDS": ( "rest_framework.filters.SearchFilter", - "rest_framework.filters.DjangoFilterBackend", + 'django_filters.rest_framework.DjangoFilterBackend', ), } diff --git a/sapl/utils.py b/sapl/utils.py index def839eb1..c884a8c48 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -21,7 +21,6 @@ from django.db.models import Q from django.utils import six, timezone from django.utils.translation import ugettext_lazy as _ import django_filters -from django_filters.filterset import STRICTNESS from easy_thumbnails import source_generators from floppyforms import ClearableFileInput import magic @@ -685,12 +684,12 @@ def qs_override_django_filter(self): valid = self.is_bound and self.form.is_valid() if self.is_bound and not valid: - if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR: + """if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR: raise forms.ValidationError(self.form.errors) - elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS: - self._qs = self.queryset.none() - return self._qs - # else STRICTNESS.IGNORE... ignoring + elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:""" + self._qs = self.queryset.none() + return self._qs + # else STRICTNESS.IGNORE... ignoring # start with all the results and filter from there qs = self.queryset.all() @@ -703,12 +702,12 @@ def qs_override_django_filter(self): try: value = self.form.fields[name].clean(raw_value) except forms.ValidationError: - if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR: + """if self.strict == STRICTNESS.RAISE_VALIDATION_ERROR: raise - elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS: - self._qs = self.queryset.none() - return self._qs - # else STRICTNESS.IGNORE... ignoring + elif bool(self.strict) == STRICTNESS.RETURN_NO_RESULTS:""" + self._qs = self.queryset.none() + return self._qs + # else STRICTNESS.IGNORE... ignoring if value is not None: # valid & clean data qs = qs._next_is_sticky()