[Python-modules-commits] [drf-haystack] 07/17: Import drf-haystack_1.5.6.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Sat Jan 2 17:45:42 UTC 2016
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository drf-haystack.
commit 35215bc7a17f7fb475a8cc7b0975aaa106c7e5db
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Sat Jan 2 17:28:50 2016 +0100
Import drf-haystack_1.5.6.orig.tar.gz
---
PKG-INFO | 2 +-
README.rst | 2 +-
docs/advanced_usage.rst | 22 +++++++++++++--
docs/conf.py | 2 +-
docs/index.rst | 57 ++++++++++++++++++++++++++++++++++++++
drf_haystack.egg-info/PKG-INFO | 2 +-
drf_haystack.egg-info/requires.txt | 1 -
drf_haystack/__init__.py | 2 +-
drf_haystack/filters.py | 25 +++++++++++++----
drf_haystack/serializers.py | 13 ++++++---
requirements.txt | 2 +-
setup.cfg | 2 +-
setup.py | 3 +-
tests/test_serializers.py | 20 +++++++++++++
tox.ini | 1 +
15 files changed, 134 insertions(+), 22 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index e1434a0..4a054d3 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: drf-haystack
-Version: 1.5.5
+Version: 1.5.6
Summary: Makes Haystack play nice with Django REST Framework
Home-page: https://github.com/inonit/drf-haystack
Author: Rolf Håvard Blindheim, Eirik Krogstad
diff --git a/README.rst b/README.rst
index a9bc670..eb4b3f7 100644
--- a/README.rst
+++ b/README.rst
@@ -32,7 +32,7 @@ Tested with the following configurations:
- Python 2.6
- Django 1.5 and 1.6
- - Python 2.7, 3.3, 3.4 and 3.5
+ - Python 2.7, 3.3 and 3.4
- Django 1.5, 1.6, 1.7 and 1.8
Installation
diff --git a/docs/advanced_usage.rst b/docs/advanced_usage.rst
index 7664628..49459fe 100644
--- a/docs/advanced_usage.rst
+++ b/docs/advanced_usage.rst
@@ -100,7 +100,7 @@ have the ``HaystackGEOSpatialFilter``.
The geospatial filter is somewhat special, and for the time being, relies on a few assumptions.
-#. The index model **must** to have a ``LocationField`` named ``coordinates`` (See :ref:`search-index-example-label` for example).
+#. The index model **must** to have a ``LocationField`` named ``coordinates`` (See :ref:`search-index-example-label` for example). If your ``LocationField`` is named differently, instead of using the ``HaystackGEOSpatialFilter``, subclass the ``BaseHaystackGEOSpatialFilter`` and provide the name of your ``LocationField`` in ``point_field`` (string).
#. The query **must** contain a ``unit`` parameter where the unit is a valid ``UNIT`` in the ``django.contrib.gis.measure.Distance`` class.
#. The query **must** contain a ``from`` parameter which is a comma separated longitude and latitude value.
@@ -134,6 +134,24 @@ The geospatial filter is somewhat special, and for the time being, relies on a f
filter_backends = [HaystackGEOSpatialFilter]
+**Example subclassing the ``BaseHaystackGEOSpatialFilter``**
+
+Assuming that your ``LocationField`` is named ``location``.
+
+.. code-block:: python
+
+ from drf_haystack.filters import BaseHaystackGEOSpatialFilter
+
+ class CustomHaystackGEOSpatialFilter(BaseHaystackGEOSpatialFilter):
+ point_field = 'location'
+
+
+ class LocationGeoSearchViewSet(HaystackViewSet):
+
+ index_models = [Location]
+ serializer_class = LocationSerializer
+ filter_backends = [CustomHaystackGEOSpatialFilter]
+
Assuming the above code works as it should, we would be able to do queries like this:
.. code-block:: none
@@ -436,7 +454,7 @@ We have a special ``HaystackFacetSerializer`` class which is designed to seriali
``get_queryset()`` method of the view to limit the queryset before it is passed on to the
``filter_facet_queryset()`` method.
-The ``HaystackFacetSerializer`` overrides a number of methods is customized to only serialize facets in a very
+The ``HaystackFacetSerializer`` overrides a number of methods and is customized to only serialize facets in a very
specific format. Using this serializer for other stuff will probably not work very good. Consider yourself warned!
Any serializer subclassed from the ``HaystackFacetSerializer`` is expected to have a ``field_options`` dictionary
diff --git a/docs/conf.py b/docs/conf.py
index ed948b8..1e5c8ab 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -76,7 +76,7 @@ copyright = '%d, Inonit AS' % date.today().year
# The short X.Y version.
version = '1.5'
# The full version, including alpha/beta/rc tags.
-release = '1.5.5'
+release = '1.5.6'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/index.rst b/docs/index.rst
index c241b47..c55eb64 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -40,8 +40,56 @@ Requirements
- Django
- Django REST Framework
- Haystack (and a supported search engine such as Solr, Elasticsearch, Whoosh, etc.)
+ - Python bindings for the chosen backend (see below).
- (geopy and libgeos if you want to use geo spatial filtering)
+Python bindings
+---------------
+
+You will also need to install python bindings for the search engine you'll use.
+
+Elasticsearch
+.............
+
+See haystack `Elasticsearch <https://django-haystack.readthedocs.org/en/v2.4.1/installing_search_engines.html#elasticsearch>`_
+docs for details
+
+.. warning::
+
+ ``django-haystack`` does not yet support Elasticsearch v2 yet, so we need to use the latest
+ 1.x branch.
+
+.. code-block:: none
+
+ $ pip install elasticsearch<2.0.0
+
+Solr
+....
+
+See haystack `Solr <https://django-haystack.readthedocs.org/en/v2.4.1/installing_search_engines.html#solr>`_
+docs for details.
+
+.. code-block:: none
+
+ $ pip install pysolr
+
+Whoosh
+......
+
+See haystack `Whoosh <https://django-haystack.readthedocs.org/en/v2.4.1/installing_search_engines.html#whoosh>`_
+docs for details.
+
+.. code-block:: none
+
+ $ pip install whoosh
+
+Xapian
+......
+
+See haystack `Xapian <https://django-haystack.readthedocs.org/en/v2.4.1/installing_search_engines.html#xapian>`_
+docs for details.
+
+
Contributors
============
@@ -56,6 +104,15 @@ Thanks guys!
Changelog
=========
+v1.5.6
+------
+*Release date: 2015-12-02*
+
+ - Fixed a bug where ``ignore_fields`` on ``HaystackSerializer`` did not work unless ``exclude`` evaluates
+ to ``True``.
+ - Removed ``elasticsearch`` from ``install_requires``. Elasticsearch should not be a mandatory requirement,
+ since it's useless if not using Elasticsearch as backend.
+
v1.5.5
------
*Release date: 2015-10-31*
diff --git a/drf_haystack.egg-info/PKG-INFO b/drf_haystack.egg-info/PKG-INFO
index e1434a0..4a054d3 100644
--- a/drf_haystack.egg-info/PKG-INFO
+++ b/drf_haystack.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: drf-haystack
-Version: 1.5.5
+Version: 1.5.6
Summary: Makes Haystack play nice with Django REST Framework
Home-page: https://github.com/inonit/drf-haystack
Author: Rolf Håvard Blindheim, Eirik Krogstad
diff --git a/drf_haystack.egg-info/requires.txt b/drf_haystack.egg-info/requires.txt
index c0fb6fc..212cc9d 100644
--- a/drf_haystack.egg-info/requires.txt
+++ b/drf_haystack.egg-info/requires.txt
@@ -1,5 +1,4 @@
Django>=1.5.0
djangorestframework>=2.4.4
django-haystack>=2.3.1
-elasticsearch<2.0.0
python-dateutil
diff --git a/drf_haystack/__init__.py b/drf_haystack/__init__.py
index 5cb2063..427a164 100644
--- a/drf_haystack/__init__.py
+++ b/drf_haystack/__init__.py
@@ -3,7 +3,7 @@
from __future__ import unicode_literals
__title__ = "drf-haystack"
-__version__ = "1.5.5"
+__version__ = "1.5.6"
__author__ = "Rolf Haavard Blindheim"
__license__ = "MIT License"
diff --git a/drf_haystack/filters.py b/drf_haystack/filters.py
index ab9617c..14e3ddf 100644
--- a/drf_haystack/filters.py
+++ b/drf_haystack/filters.py
@@ -140,17 +140,22 @@ class HaystackAutocompleteFilter(HaystackFilter):
return six.moves.reduce(operator.and_, filter(lambda x: x, query_bits))
-class HaystackGEOSpatialFilter(HaystackFilter):
+class BaseHaystackGEOSpatialFilter(HaystackFilter):
"""
- A filter backend for doing geospatial filtering.
- If using this filter make sure your index has a `LocationField`
- named `coordinates`.
+ A base filter backend for doing geospatial filtering.
+ If using this filter make sure to provide a `point_field` with the name of
+ your the `LocationField` of your index.
We'll always do the somewhat slower but more accurate `dwithin`
(radius) filter.
"""
+ point_field = None
def __init__(self, *args, **kwargs):
+ if not self.point_field:
+ raise ImproperlyConfigured("You should provide `point_field` in "
+ "your subclassed geo-spatial filter "
+ "class.")
try:
from haystack.utils.geo import D, Point
self.D = D
@@ -200,7 +205,7 @@ class HaystackGEOSpatialFilter(HaystackFilter):
distance = self.unit_to_meters(self.D(**distance)) # pragma: no cover
else:
distance = self.D(**distance)
- queryset = queryset.dwithin("coordinates", point, distance).distance("coordinates", point)
+ queryset = queryset.dwithin(self.point_field, point, distance).distance(self.point_field, point)
except ValueError:
raise ValueError("Cannot convert `from=latitude,longitude` query parameter to "
"float values. Make sure to provide numerical values only!")
@@ -209,7 +214,15 @@ class HaystackGEOSpatialFilter(HaystackFilter):
def filter_queryset(self, request, queryset, view):
queryset = self.geo_filter(queryset, filters=self.get_request_filters(request))
- return super(HaystackGEOSpatialFilter, self).filter_queryset(request, queryset, view)
+ return super(BaseHaystackGEOSpatialFilter, self).filter_queryset(request, queryset, view)
+
+
+class HaystackGEOSpatialFilter(BaseHaystackGEOSpatialFilter):
+ """
+ If using this filter make sure your index has a `LocationField`
+ named `coordinates`.
+ """
+ point_field = 'coordinates'
class HaystackHighlightFilter(HaystackFilter):
diff --git a/drf_haystack/serializers.py b/drf_haystack/serializers.py
index 130a04d..5f519b0 100644
--- a/drf_haystack/serializers.py
+++ b/drf_haystack/serializers.py
@@ -136,12 +136,17 @@ class HaystackSerializer(serializers.Serializer):
orig_name = field_name
field_name = "%s%s" % (prefix, field_name)
- # This has become a little more complex, but provides convenient flexibility for users
- if not exclude:
+ # Don't use this field if it is in `ignore_fields`
+ if orig_name in ignore_fields or field_name in ignore_fields:
+ continue
+ # When fields to include are decided by `exclude`
+ if exclude:
+ if orig_name in exclude or field_name in exclude:
+ continue
+ # When fields to include are decided by `fields`
+ if fields:
if orig_name not in fields and field_name not in fields:
continue
- elif orig_name in exclude or field_name in exclude or orig_name in ignore_fields or field_name in ignore_fields:
- continue
# Look up the field attributes on the current index model,
# in order to correctly instantiate the serializer field.
diff --git a/requirements.txt b/requirements.txt
index 7048b79..599e62a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,7 +3,7 @@ Sphinx
coverage
django-haystack
djangorestframework
-elasticsearch
+elasticsearch<2.0.0
nose
sphinx-rtd-theme
urllib3
diff --git a/setup.cfg b/setup.cfg
index 6bc2ff3..ebbec92 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
[egg_info]
-tag_date = 0
tag_build =
tag_svn_revision = 0
+tag_date = 0
diff --git a/setup.py b/setup.py
index 9599f13..696709d 100644
--- a/setup.py
+++ b/setup.py
@@ -36,14 +36,13 @@ setup(
"Django>=1.5.0",
"djangorestframework>=2.4.4",
"django-haystack>=2.3.1",
- "elasticsearch<2.0.0",
"python-dateutil"
],
tests_require=[
"nose",
"coverage",
"unittest2",
- "elasticsearch>=1.4.0",
+ "elasticsearch<2.0.0",
],
zip_safe=False,
test_suite="tests.runtests.start",
diff --git a/tests/test_serializers.py b/tests/test_serializers.py
index 7f38616..c173a9e 100644
--- a/tests/test_serializers.py
+++ b/tests/test_serializers.py
@@ -131,6 +131,13 @@ class HaystackSerializerTestCase(WarningTestCaseMixin, TestCase):
index_classes = [MockPersonIndex]
exclude = ["firstname"]
+ class Serializer6(HaystackSerializer):
+
+ class Meta:
+ index_classes = [MockPersonIndex]
+ fields = ["text", "firstname", "lastname", "autocomplete"]
+ ignore_fields = ["autocomplete"]
+
class ViewSet1(HaystackViewSet):
serializer_class = Serializer3
@@ -145,6 +152,7 @@ class HaystackSerializerTestCase(WarningTestCaseMixin, TestCase):
self.serializer3 = Serializer3
self.serializer4 = Serializer4
self.serializer5 = Serializer5
+ self.serializer6 = Serializer6
self.view1 = ViewSet1
self.view2 = ViewSet2
@@ -207,6 +215,18 @@ class HaystackSerializerTestCase(WarningTestCaseMixin, TestCase):
assert isinstance(fields["lastname"], CharField), self.fail("serializer 'lastname' field is not a CharField instance")
assert isinstance(fields["autocomplete"], CharField), self.fail("serializer 'autocomplete' field is not a CharField instance")
+ def test_serializer_get_fields_with_ignore_fields(self):
+ from rest_framework.fields import CharField
+
+ obj = SearchQuerySet().filter(lastname="Foreman")[0]
+ serializer = self.serializer6(instance=obj)
+ fields = serializer.get_fields()
+ assert isinstance(fields, dict), self.fail("serializer.data is not a dict")
+ assert isinstance(fields["text"], CharField), self.fail("serializer 'text' field is not a CharField instance")
+ assert isinstance(fields["firstname"], CharField), self.fail("serializer 'firtname' field is not a CharField instance")
+ assert isinstance(fields["lastname"], CharField), self.fail("serializer 'lastname' field is not a CharField instance")
+ assert "autocomplete" not in fields, self.fail("serializer 'autocomplete' should not be present")
+
class HaystackSerializerMultipleIndexTestCase(WarningTestCaseMixin, TestCase):
diff --git a/tox.ini b/tox.ini
index a14d8e8..749953d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -22,6 +22,7 @@ envlist =
[base]
deps =
+ elasticsearch<2.0.0
[django1.5]
deps =
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/drf-haystack.git
More information about the Python-modules-commits
mailing list