Skip to content

Commit 11ea016

Browse files
committed
Remove haystack v1 support
1 parent e6650e9 commit 11ea016

File tree

6 files changed

+17
-103
lines changed

6 files changed

+17
-103
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ before_install:
88
- export DJANGO_SETTINGS_MODULE=celery_haystack.test_settings
99
install:
1010
- pip install -e .
11-
- pip install -r requirements/$HAYSTACK.txt $DJANGO
11+
- pip install -r requirements/v2.txt $DJANGO
1212
before_script:
1313
- flake8 celery_haystack --ignore=E501
1414
script:
1515
- coverage run --branch --source=celery_haystack `which django-admin.py` test celery_haystack
1616
- coverage report --omit=celery_haystack/test*
1717
env:
18-
- DJANGO="Django==1.8.7" HAYSTACK=v2
19-
- DJANGO="Django==1.9" HAYSTACK=v2
18+
- DJANGO="Django==1.8.7"
19+
- DJANGO="Django==1.9"
2020
matrix:
2121
exclude:
22-
- env: DJANGO="Django==1.9" HAYSTACK=v2
22+
- env: DJANGO="Django==1.9"
2323
python: "3.3"

celery_haystack/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.conf import settings # noqa
22
from django.core.exceptions import ImproperlyConfigured
3-
from haystack import constants, __version__ as haystack_version
3+
from haystack import constants
44
from haystack.management.commands import update_index as cmd
55
from appconf import AppConf
66

@@ -56,7 +56,7 @@ def configure(self):
5656
signal_processor = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', None)
5757

5858

59-
if haystack_version[0] >= 2 and signal_processor is None:
59+
if signal_processor is None:
6060
raise ImproperlyConfigured("When using celery-haystack with Haystack 2.X "
6161
"the HAYSTACK_SIGNAL_PROCESSOR setting must be "
6262
"set. Use 'celery_haystack.signals."

celery_haystack/indexes.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
from django.db.models import signals
2-
31
from haystack import indexes
42

5-
from .utils import enqueue_task
6-
73

84
class CelerySearchIndex(indexes.SearchIndex):
9-
"""
10-
A ``SearchIndex`` subclass that enqueues updates/deletes for later
11-
processing using Celery.
12-
"""
13-
# We override the built-in _setup_* methods to connect the enqueuing
14-
# operation.
15-
def _setup_save(self, model):
16-
signals.post_save.connect(self.enqueue_save,
17-
sender=model,
18-
dispatch_uid=CelerySearchIndex)
19-
20-
def _setup_delete(self, model):
21-
signals.post_delete.connect(self.enqueue_delete,
22-
sender=model,
23-
dispatch_uid=CelerySearchIndex)
24-
25-
def _teardown_save(self, model):
26-
signals.post_save.disconnect(self.enqueue_save,
27-
sender=model,
28-
dispatch_uid=CelerySearchIndex)
29-
30-
def _teardown_delete(self, model):
31-
signals.post_delete.disconnect(self.enqueue_delete,
32-
sender=model,
33-
dispatch_uid=CelerySearchIndex)
34-
35-
def enqueue_save(self, instance, **kwargs):
36-
if not getattr(instance, 'skip_indexing', False):
37-
return self.enqueue('update', instance)
38-
39-
def enqueue_delete(self, instance, **kwargs):
40-
if not getattr(instance, 'skip_indexing', False):
41-
return self.enqueue('delete', instance)
42-
43-
def enqueue(self, action, instance):
44-
"""
45-
Shoves a message about how to update the index into the queue.
46-
47-
This is a standardized string, resembling something like::
48-
49-
``notes.note.23``
50-
# ...or...
51-
``weblog.entry.8``
52-
"""
53-
return enqueue_task(action, instance)
5+
pass

celery_haystack/tasks.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
from django.core.exceptions import ImproperlyConfigured
22
from django.core.management import call_command
3-
try:
4-
from django.apps import apps
5-
get_model = apps.get_model
6-
except ImportError:
7-
from django.db.models.loading import get_model
3+
from django.apps import apps
4+
get_model = apps.get_model
85

96
from .conf import settings
107

11-
try:
12-
from haystack import connections, connection_router
13-
from haystack.exceptions import NotHandled as IndexNotFoundException
14-
legacy = False
15-
except ImportError:
16-
try:
17-
from haystack import site
18-
from haystack.exceptions import NotRegistered as IndexNotFoundException # noqa
19-
legacy = True
20-
except ImportError as e:
21-
raise ImproperlyConfigured("Haystack couldn't be imported: %s" % e)
22-
23-
if settings.CELERY_HAYSTACK_TRANSACTION_SAFE and not getattr(settings, 'CELERY_ALWAYS_EAGER', False):
24-
from djcelery_transactions import PostTransactionTask as Task
25-
else:
26-
from celery.task import Task # noqa
8+
from haystack import connections, connection_router
9+
from haystack.exceptions import NotHandled as IndexNotFoundException
2710

11+
from celery.task import Task # noqa
2812
from celery.utils.log import get_task_logger
2913

3014
logger = get_task_logger(__name__)
@@ -87,14 +71,10 @@ def get_indexes(self, model_class, **kwargs):
8771
Fetch the model's registered ``SearchIndex`` in a standarized way.
8872
"""
8973
try:
90-
if legacy:
91-
index_holder = site
92-
yield index_holder.get_index(model_class), self.using
93-
else:
94-
using_backends = connection_router.for_write(**{'models': [model_class]})
95-
for using in using_backends:
96-
index_holder = connections[using].get_unified_index()
97-
yield index_holder.get_index(model_class), using
74+
using_backends = connection_router.for_write(**{'models': [model_class]})
75+
for using in using_backends:
76+
index_holder = connections[using].get_unified_index()
77+
yield index_holder.get_index(model_class), using
9878
except IndexNotFoundException:
9979
raise ImproperlyConfigured("Couldn't find a SearchIndex for %s." %
10080
model_class)
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
from haystack import indexes, __version__ as haystack_version
1+
from haystack import indexes
22

33
from .models import Note
44
from ..indexes import CelerySearchIndex
55

6-
if haystack_version[:2] < (2, 0):
7-
from haystack import site
8-
9-
class Indexable(object):
10-
pass
11-
indexes.Indexable = Indexable
12-
else:
13-
site = None # noqa
14-
156

167
# Simplest possible subclass that could work.
178
class NoteIndex(CelerySearchIndex, indexes.Indexable):
189
text = indexes.CharField(document=True, model_attr='content')
1910

2011
def get_model(self):
2112
return Note
22-
23-
if site:
24-
site.register(Note, NoteIndex)

requirements/v1.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)