Merge pull request #1397 from emanuelschuetze/haystack-fix

Fixed haystack indexing problem for m2m objects.
This commit is contained in:
Norman Jäckel 2015-01-17 00:21:45 +01:00
commit 82f46708f6
5 changed files with 39 additions and 2 deletions

View File

@ -10,6 +10,8 @@ Version 1.7 (unreleased)
Core: Core:
- New feature to tag motions, agenda and assignments. - 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: motion:
- New Feature to create amendments, which are related to a parent motion. - New Feature to create amendments, which are related to a parent motion.

View File

@ -33,6 +33,18 @@ class AssignmentCandidate(RelatedModelMixin, models.Model):
class Meta: class Meta:
unique_together = ("assignment", "person") 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): def __unicode__(self):
return unicode(self.person) return unicode(self.person)

View File

@ -128,7 +128,7 @@ HAYSTACK_CONNECTIONS = {
} }
# Haystack updates search index after each save/delete action by apps # 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 # Adds all automaticly collected plugins
INSTALLED_PLUGINS = collect_plugins() INSTALLED_PLUGINS = collect_plugins()

View 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)

View File

@ -3,7 +3,7 @@ Django>=1.5,<1.7
beautifulsoup4>=4.3,<4.4 beautifulsoup4>=4.3,<4.4
bleach>=1.2,<1.5 bleach>=1.2,<1.5
django-ckeditor-updated>=4.2,<4.3 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 django-mptt>=0.6,<0.7
jsonfield>=0.9,<0.10 jsonfield>=0.9,<0.10
natsort>=3.2,<3.3 natsort>=3.2,<3.3