Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,20 @@ jobs:
fail-fast: false

matrix:
python-version: ["2.7", "3.6", "3.7", "3.8"]
django-version: ["1.11", "2.0", "2.2", "2.1", "3.0"]
python-version: ["3.6", "3.7", "3.8", "3.9"]
django-version: ["2.0", "2.2", "2.1", "3.0"]
es-dsl-version: ["6.4", "7.4"]
es-version: ["7.13.4"]

exclude:
- python-version: "2.7"
django-version: "2.0"
- python-version: "2.7"
django-version: "2.1"
- python-version: "2.7"
django-version: "2.2"
- python-version: "2.7"
django-version: "3.0"

- python-version: "3.8"
django-version: "1.11"
- python-version: "3.8"
django-version: "2.0"
- python-version: "3.8"
django-version: "2.1"
- python-version: "3.9"
django-version: "2.0"
- python-version: "3.9"
django-version: "2.1"

steps:
- name: Install and Run Elasticsearch
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Features
- Index fast using `parallel` indexing.
- Requirements

- Django >= 1.11
- Python 2.7, 3.5, 3.6, 3.7, 3.8
- Django 2.0+
- Python 3.6+

**Elasticsearch Compatibility:**
The library is compatible with all Elasticsearch versions since 5.x
Expand Down
9 changes: 4 additions & 5 deletions django_elasticsearch_dsl/documents.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from __future__ import unicode_literals

from collections import deque
from functools import partial

from django import VERSION as DJANGO_VERSION
from django.db import models
from elasticsearch.helpers import bulk, parallel_bulk
from elasticsearch_dsl import Document as DSLDocument
from six import iteritems

from .exceptions import ModelFieldNotMappedError
from .fields import (
Expand Down Expand Up @@ -51,8 +48,10 @@
models.UUIDField: KeywordField,
}


class DocType(DSLDocument):
_prepared_fields = []

def __init__(self, related_instance_to_ignore=None, **kwargs):
super(DocType, self).__init__(**kwargs)
self._related_instance_to_ignore = related_instance_to_ignore
Expand Down Expand Up @@ -97,7 +96,7 @@ def init_prepare(self):
"""
index_fields = getattr(self, '_fields', {})
fields = []
for name, field in iteritems(index_fields):
for name, field in index_fields.items():
if not isinstance(field, DEDField):
continue

Expand Down Expand Up @@ -201,7 +200,7 @@ def _bulk(self, *args, **kwargs):

def should_index_object(self, obj):
"""
Overwriting this method and returning a boolean value
Overwriting this method and returning a boolean value
should determine whether the object should be indexed.
"""
return True
Expand Down
1 change: 0 additions & 1 deletion django_elasticsearch_dsl/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
from types import MethodType

from django.core.exceptions import ObjectDoesNotExist
Expand Down
2 changes: 0 additions & 2 deletions django_elasticsearch_dsl/indices.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from copy import deepcopy

from elasticsearch_dsl import Index as DSLIndex
from six import python_2_unicode_compatible

from .apps import DEDConfig
from .registries import registry


@python_2_unicode_compatible
class Index(DSLIndex):
def __init__(self, *args, **kwargs):
super(Index, self).__init__(*args, **kwargs)
Expand Down
3 changes: 0 additions & 3 deletions django_elasticsearch_dsl/management/commands/search_index.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import unicode_literals, absolute_import

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from six.moves import input
from ...registries import registry


Expand Down
13 changes: 6 additions & 7 deletions django_elasticsearch_dsl/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ImproperlyConfigured
from elasticsearch_dsl import Field, AttrDict
from six import itervalues, iterkeys, iteritems
from elasticsearch_dsl import AttrDict

from django_elasticsearch_dsl.exceptions import RedeclaredFieldError
from .apps import DEDConfig
Expand All @@ -28,7 +27,7 @@ def register(self, index, doc_class):
for related in doc_class.django.related_models:
self._related_models[related].add(doc_class.django.model)

for idx, docs in iteritems(self._indices):
for idx, docs in self._indices.items():
if index._name == idx._name:
docs.add(doc_class)
return
Expand Down Expand Up @@ -154,25 +153,25 @@ def get_documents(self, models=None):
if models is not None:
return set(chain.from_iterable(self._models[model] for model in models
if model in self._models))
return set(chain.from_iterable(itervalues(self._indices)))
return set(chain.from_iterable(self._indices.values()))

def get_models(self):
"""
Get all models in the registry
"""
return set(iterkeys(self._models))
return set(self._models.keys())

def get_indices(self, models=None):
"""
Get all indices in the registry or the indices for a list of models
"""
if models is not None:
return set(
indice for indice, docs in iteritems(self._indices)
indice for indice, docs in self._indices.items()
for doc in docs if doc.django.model in models
)

return set(iterkeys(self._indices))
return set(self._indices.keys())


registry = DocumentRegistry()
3 changes: 0 additions & 3 deletions django_elasticsearch_dsl/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# encoding: utf-8
"""
A convenient way to attach django-elasticsearch-dsl to Django's signals and
cause things to index.
"""

from __future__ import absolute_import

from django.db import models
from django.dispatch import Signal

Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand Down
3 changes: 0 additions & 3 deletions example/test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-11-21 18:46
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

Expand Down
7 changes: 0 additions & 7 deletions example/test_app/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from six import python_2_unicode_compatible


@python_2_unicode_compatible
class Car(models.Model):
TYPE_CHOICES = (
('se', "Sedan"),
Expand Down Expand Up @@ -37,7 +33,6 @@ def __str__(self):
}


@python_2_unicode_compatible
class Manufacturer(models.Model):
name = models.CharField(max_length=255)
country_code = models.CharField(max_length=2)
Expand All @@ -51,7 +46,6 @@ def __str__(self):
return self.name


@python_2_unicode_compatible
class Category(models.Model):
title = models.CharField(max_length=255)
slug = models.CharField(max_length=255)
Expand All @@ -60,7 +54,6 @@ def __str__(self):
return self.title


@python_2_unicode_compatible
class Ad(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
Expand Down
12 changes: 3 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys

Expand Down Expand Up @@ -41,30 +40,25 @@
'django_elasticsearch_dsl',
],
include_package_data=True,
install_requires=[
'elasticsearch-dsl>=7.2.0<8.0.0',
'six',
],
install_requires=['elasticsearch-dsl>=7.2.0<8.0.0'],
license="Apache Software License 2.0",
zip_safe=False,
keywords='django elasticsearch elasticsearch-dsl',
classifiers=[
'Development Status :: 3 - Alpha',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.2',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
)
3 changes: 2 additions & 1 deletion tests/documents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from elasticsearch_dsl import analyzer
from django_elasticsearch_dsl import Document, Index, fields
from django_elasticsearch_dsl import Document, fields
from django_elasticsearch_dsl.registries import registry

from .models import Ad, Category, Car, Manufacturer, Article
Expand Down Expand Up @@ -160,6 +160,7 @@ class Index:
name = 'test_articles'
settings = index_settings


@registry.register_document
class ArticleWithSlugAsIdDocument(Document):
class Django:
Expand Down
8 changes: 0 additions & 8 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from six import python_2_unicode_compatible


@python_2_unicode_compatible
class Car(models.Model):
TYPE_CHOICES = (
('se', "Sedan"),
Expand Down Expand Up @@ -41,7 +37,6 @@ def __str__(self):
}


@python_2_unicode_compatible
class Manufacturer(models.Model):
name = models.CharField(max_length=255, default=_("Test lazy tanslation"))
country_code = models.CharField(max_length=2)
Expand All @@ -58,7 +53,6 @@ def __str__(self):
return self.name


@python_2_unicode_compatible
class Category(models.Model):
title = models.CharField(max_length=255)
slug = models.CharField(max_length=255)
Expand All @@ -71,7 +65,6 @@ def __str__(self):
return self.title


@python_2_unicode_compatible
class Ad(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
Expand All @@ -89,7 +82,6 @@ def __str__(self):
return self.title


@python_2_unicode_compatible
class Article(models.Model):
slug = models.CharField(
max_length=255,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from io import StringIO

from mock import DEFAULT, Mock, patch
from unittest import TestCase

from django.core.management.base import CommandError
from django.core.management import call_command
from six import StringIO

from django_elasticsearch_dsl import Index
from django_elasticsearch_dsl.management.commands.search_index import Command
Expand Down
13 changes: 6 additions & 7 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

from django.db import models
from django.utils.translation import ugettext_lazy as _
from elasticsearch_dsl import GeoPoint, MetaField
from mock import patch, Mock, PropertyMock
from elasticsearch_dsl import GeoPoint
from mock import patch, Mock

from django_elasticsearch_dsl import fields
from django_elasticsearch_dsl.documents import DocType, Document
from django_elasticsearch_dsl.documents import DocType
from django_elasticsearch_dsl.exceptions import (ModelFieldNotMappedError,
RedeclaredFieldError)
from django_elasticsearch_dsl.registries import registry
from tests import ES_MAJOR_VERSION

from .models import Article
from .documents import ArticleDocument, ArticleWithSlugAsIdDocument


class Car(models.Model):
Expand Down Expand Up @@ -353,7 +352,7 @@ def test_init_prepare_correct(self):

expect = {
'color': ("<class 'django_elasticsearch_dsl.fields.TextField'>",
("<class 'method'>", "<type 'instancemethod'>")), # py3, py2
("<class 'method'>", "<type 'instancemethod'>")), # py3, py2
'type': ("<class 'django_elasticsearch_dsl.fields.TextField'>",
("<class 'functools.partial'>","<type 'functools.partial'>")),
'name': ("<class 'django_elasticsearch_dsl.fields.TextField'>",
Expand All @@ -375,8 +374,8 @@ def test_init_prepare_results(self):
car = Car()
setattr(car, 'name', "Tusla")
setattr(car, 'price', 340123.21)
setattr(car, 'color', "polka-dots") # Overwritten by prepare function
setattr(car, 'pk', 4701) # Ignored, not in document
setattr(car, 'color', "polka-dots") # Overwritten by prepare function
setattr(car, 'pk', 4701) # Ignored, not in document
setattr(car, 'type', "imaginary")

self.assertEqual(d.prepare(car), {'color': 'blue', 'type': 'imaginary', 'name': 'Tusla', 'price': 340123.21})
Expand Down
5 changes: 1 addition & 4 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db.models.fields.files import FieldFile
from django.utils.translation import ugettext_lazy as _
from mock import Mock, NonCallableMock
from six import string_types

from django_elasticsearch_dsl.exceptions import VariableLookupError
from django_elasticsearch_dsl.fields import (BooleanField, ByteField, CompletionField, DEDField,
Expand Down Expand Up @@ -63,9 +62,7 @@ def test_get_value_from_none(self):
def test_get_value_from_lazy_object(self):
field = DEDField(attr='translation')
instance = NonCallableMock(translation=_("foo"))
self.assertIsInstance(
field.get_value_from_instance(instance), string_types
)
self.assertIsInstance(field.get_value_from_instance(instance), str)
self.assertEqual(field.get_value_from_instance(instance), "foo")


Expand Down
Loading