From 2c095472300c59072f4c713d9c6da49995484e0c Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 2 Nov 2016 12:52:55 +0100 Subject: [PATCH 1/7] Update restframework3.py --- django_elasticsearch/contrib/restframework/restframework3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_elasticsearch/contrib/restframework/restframework3.py b/django_elasticsearch/contrib/restframework/restframework3.py index 090cc1e..1216a90 100644 --- a/django_elasticsearch/contrib/restframework/restframework3.py +++ b/django_elasticsearch/contrib/restframework/restframework3.py @@ -87,7 +87,7 @@ def filter_queryset(self, queryset): def dispatch(self, request, *args, **kwargs): try: r = super(IndexableModelMixin, self).dispatch(request, *args, **kwargs) - except (ConnectionError, TransportError), e: + except (ConnectionError, TransportError) as e: # reset object list self.queryset = None self.es_failed = True From 77c42872b8dfe0d0e991265240b3a8609e2d0d88 Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 2 Nov 2016 12:57:42 +0100 Subject: [PATCH 2/7] SyntaxError: except (ConnectionError, ...), e: --- django_elasticsearch/contrib/restframework/restframework2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_elasticsearch/contrib/restframework/restframework2.py b/django_elasticsearch/contrib/restframework/restframework2.py index e17b7a2..b5507ca 100644 --- a/django_elasticsearch/contrib/restframework/restframework2.py +++ b/django_elasticsearch/contrib/restframework/restframework2.py @@ -147,7 +147,7 @@ def list(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs): try: r = super(IndexableModelMixin, self).dispatch(request, *args, **kwargs) - except (ConnectionError, TransportError), e: + except (ConnectionError, TransportError) as e: # reset object list self.queryset = None self.es_failed = True From 50f57490a01f00a0b863df5b9313c513cd3a880f Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 2 Nov 2016 15:08:45 +0100 Subject: [PATCH 3/7] Update managers.py --- django_elasticsearch/managers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django_elasticsearch/managers.py b/django_elasticsearch/managers.py index edf2718..dcb50a5 100644 --- a/django_elasticsearch/managers.py +++ b/django_elasticsearch/managers.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import json +from django.utils import six try: import importlib except ImportError: # python < 2.7 @@ -87,7 +88,7 @@ def check_cluster(self): def get_serializer(self, **kwargs): serializer = self.model.Elasticsearch.serializer_class - if isinstance(serializer, basestring): + if isinstance(serializer, basestring if six.PY2: else str): module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1) mod = importlib.import_module(module) return getattr(mod, kls)(self.model, **kwargs) From c713e4d0c610364b4d9af7335f7d16b6015ca8d3 Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 2 Nov 2016 15:10:03 +0100 Subject: [PATCH 4/7] Typo error. --- django_elasticsearch/managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_elasticsearch/managers.py b/django_elasticsearch/managers.py index dcb50a5..9cbfce5 100644 --- a/django_elasticsearch/managers.py +++ b/django_elasticsearch/managers.py @@ -88,7 +88,7 @@ def check_cluster(self): def get_serializer(self, **kwargs): serializer = self.model.Elasticsearch.serializer_class - if isinstance(serializer, basestring if six.PY2: else str): + if isinstance(serializer, basestring if six.PY2 else str): module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1) mod = importlib.import_module(module) return getattr(mod, kls)(self.model, **kwargs) From fca5e9fca6723bfa93c14cd6d04e848a28c0cc2f Mon Sep 17 00:00:00 2001 From: Nekmo Date: Thu, 24 Nov 2016 13:35:22 +0100 Subject: [PATCH 5/7] Replace iteritems to items. --- django_elasticsearch/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_elasticsearch/utils.py b/django_elasticsearch/utils.py index 1b05ad9..221c31b 100644 --- a/django_elasticsearch/utils.py +++ b/django_elasticsearch/utils.py @@ -2,7 +2,7 @@ def nested_update(d, u): - for k, v in u.iteritems(): + for k, v in u.items(): if isinstance(v, collections.Mapping): r = nested_update(d.get(k, {}), v) d[k] = r @@ -20,4 +20,4 @@ def dict_depth(d, depth=0): if not isinstance(d, dict) or not d: return depth return max(dict_depth(v, depth + 1) - for k, v in d.iteritems()) + for k, v in d.items()) From 3be979c1f6bdf727df780b214831f54de66c418a Mon Sep 17 00:00:00 2001 From: Nekmo Date: Wed, 8 Mar 2017 19:00:55 +0100 Subject: [PATCH 6/7] six.text_type instead unicode. --- django_elasticsearch/serializers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_elasticsearch/serializers.py b/django_elasticsearch/serializers.py index 474e64e..4a86553 100644 --- a/django_elasticsearch/serializers.py +++ b/django_elasticsearch/serializers.py @@ -3,7 +3,7 @@ from django.db.models import FieldDoesNotExist from django.db.models.fields.related import ManyToManyField - +from django.utils import six class EsSerializer(object): def serialize(self, instance): @@ -145,7 +145,7 @@ def nested_serialize(self, rel): return obj # Fallback on a dict with id + __unicode__ value of the related model instance. - return dict(id=rel.pk, value=unicode(rel)) + return dict(id=rel.pk, value=six.text_type(rel)) def format(self, instance): # from a model instance to a dict From 414bad5b6f5c621cb5045443578efe3a366619c9 Mon Sep 17 00:00:00 2001 From: nekmo Date: Thu, 9 Mar 2017 14:34:11 +0100 Subject: [PATCH 7/7] Six iteritems. --- django_elasticsearch/contrib/restframework/restframework2.py | 3 ++- django_elasticsearch/contrib/restframework/restframework3.py | 3 ++- django_elasticsearch/serializers.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django_elasticsearch/contrib/restframework/restframework2.py b/django_elasticsearch/contrib/restframework/restframework2.py index b5507ca..a6058e9 100644 --- a/django_elasticsearch/contrib/restframework/restframework2.py +++ b/django_elasticsearch/contrib/restframework/restframework2.py @@ -10,6 +10,7 @@ from rest_framework.filters import DjangoFilterBackend from django_elasticsearch.models import EsIndexable +from django.utils import six from elasticsearch import NotFoundError @@ -75,7 +76,7 @@ def filter_queryset(self, request, queryset, view): filterable = getattr(view, 'filter_fields', []) filters = dict([(k, v) - for k, v in request.GET.iteritems() + for k, v in six.iteritems(request.GET) if k in filterable]) q = queryset.query(query).filter(**filters) diff --git a/django_elasticsearch/contrib/restframework/restframework3.py b/django_elasticsearch/contrib/restframework/restframework3.py index 1216a90..4c311ad 100644 --- a/django_elasticsearch/contrib/restframework/restframework3.py +++ b/django_elasticsearch/contrib/restframework/restframework3.py @@ -8,6 +8,7 @@ from rest_framework.filters import DjangoFilterBackend from django_elasticsearch.models import EsIndexable +from django.utils import six try: @@ -38,7 +39,7 @@ def filter_queryset(self, request, queryset, view): filterable = getattr(view, 'filter_fields', []) filters = dict([(k, v) - for k, v in request.GET.iteritems() + for k, v in six.iteritems(request.GET) if k in filterable]) q = queryset.query(query).filter(**filters) diff --git a/django_elasticsearch/serializers.py b/django_elasticsearch/serializers.py index 4a86553..049d32a 100644 --- a/django_elasticsearch/serializers.py +++ b/django_elasticsearch/serializers.py @@ -81,7 +81,7 @@ def deserialize(self, source): Returns a model instance """ attrs = {} - for k, v in source.iteritems(): + for k, v in six.iteritems(source): try: attrs[k] = self.deserialize_field(source, k) except (AttributeError, FieldDoesNotExist):