Merge pull request #1397 from emanuelschuetze/haystack-fix
Fixed haystack indexing problem for m2m objects.
This commit is contained in:
commit
82f46708f6
@ -10,6 +10,8 @@ Version 1.7 (unreleased)
|
||||
|
||||
Core:
|
||||
- New feature to tag motions, agenda and assignments.
|
||||
- Fixed search index problem to index contents of many-to-many table
|
||||
(e.g. tags of a motion).
|
||||
|
||||
motion:
|
||||
- New Feature to create amendments, which are related to a parent motion.
|
||||
|
@ -33,6 +33,18 @@ class AssignmentCandidate(RelatedModelMixin, models.Model):
|
||||
class Meta:
|
||||
unique_together = ("assignment", "person")
|
||||
|
||||
# Will be removed in 2.0 (required for haystack fix)
|
||||
def save(self, *args, **kwargs):
|
||||
super(AssignmentCandidate, self).save(*args, **kwargs)
|
||||
models.signals.m2m_changed.send(sender=self, action='post_add',
|
||||
instance=self.assignment)
|
||||
|
||||
# Will be removed in 2.0 (required for haystack fix)
|
||||
def delete(self, *args, **kwargs):
|
||||
super(AssignmentCandidate, self).delete(*args, **kwargs)
|
||||
models.signals.m2m_changed.send(sender=self, action='post_remove',
|
||||
instance=self.assignment)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.person)
|
||||
|
||||
|
@ -128,7 +128,7 @@ HAYSTACK_CONNECTIONS = {
|
||||
}
|
||||
|
||||
# Haystack updates search index after each save/delete action by apps
|
||||
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
|
||||
HAYSTACK_SIGNAL_PROCESSOR = 'openslides.utils.haystack_processor.OpenSlidesProcessor'
|
||||
|
||||
# Adds all automaticly collected plugins
|
||||
INSTALLED_PLUGINS = collect_plugins()
|
||||
|
23
openslides/utils/haystack_processor.py
Normal file
23
openslides/utils/haystack_processor.py
Normal file
@ -0,0 +1,23 @@
|
||||
from django.db import models
|
||||
from haystack.signals import RealtimeSignalProcessor
|
||||
|
||||
|
||||
class OpenSlidesProcessor(RealtimeSignalProcessor):
|
||||
def setup(self):
|
||||
# Naive (listen to all model saves).
|
||||
super(OpenSlidesProcessor, self).setup()
|
||||
models.signals.m2m_changed.connect(self.handle_many_to_many)
|
||||
|
||||
def teardown(self):
|
||||
# Naive (listen to all model saves).
|
||||
super(OpenSlidesProcessor, self).teardown()
|
||||
models.signals.m2m_changed.disconnect(self.handle_many_to_many)
|
||||
|
||||
def handle_many_to_many(self, sender, instance, **kwargs):
|
||||
"""
|
||||
Given an individual model instance, determine which backends the
|
||||
update should be sent to & update the object on those backends.
|
||||
"""
|
||||
model_class = type(instance)
|
||||
if kwargs['action'] == 'post_add' or kwargs['action'] == 'post_clear' or kwargs['action'] == 'post_remove':
|
||||
self.handle_save(model_class, instance, **kwargs)
|
@ -3,7 +3,7 @@ Django>=1.5,<1.7
|
||||
beautifulsoup4>=4.3,<4.4
|
||||
bleach>=1.2,<1.5
|
||||
django-ckeditor-updated>=4.2,<4.3
|
||||
django-haystack>=2.1,<2.2
|
||||
django-haystack>=2.1,<2.4
|
||||
django-mptt>=0.6,<0.7
|
||||
jsonfield>=0.9,<0.10
|
||||
natsort>=3.2,<3.3
|
||||
|
Loading…
Reference in New Issue
Block a user