Last active
August 29, 2015 14:22
-
-
Save gavinwahl/ed04f9e4346a78d283b7 to your computer and use it in GitHub Desktop.
RealtimeSignalProcessor for widgy that understands making commits need to reindex their owners.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from haystack.signals import RealtimeSignalProcessor | |
from widgy.models.versioning import VersionCommit | |
class WidgyRealtimeSignalProcessor(RealtimeSignalProcessor): | |
def handle_commit(self, sender, instance, **kwargs): | |
for owner in instance.tracker.owners: | |
self.handle_save(sender=type(owner), instance=owner, **kwargs) | |
def setup(self): | |
super(WidgyRealtimeSignalProcessor, self).setup() | |
models.signals.post_save.connect(self.handle_commit, sender=VersionCommit) | |
def teardown(self): | |
super(WidgyRealtimeSignalProcessor, self).teardown() | |
models.signals.post_save.disconnect(self.handle_commit, sender=VersionCommit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment