Last active
August 29, 2015 13:55
-
-
Save cooncesean/8702673 to your computer and use it in GitHub Desktop.
Signal handler configuration.
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.models.signals import post_save, post_delete | |
from django.dispatch import receiver | |
from models import SomeModel, AnotherModel | |
@receiver(post_save, sender=SomeModel) | |
@receiver(post_save, sender=AnotherModel) | |
def push_object_to_external_services(sender, instance, created, **kwargs): | |
" Send updates to any bound external services. " | |
# .... logic to get all of the services this object needs to get sent to .... | |
for external_service in external_services: | |
# Instantiate the ExternalService's Synchronizer | |
synchronizer = external_service.get_synchronizer() | |
# Set the `CRUD` option (either create or update) | |
crud_option = created and 'create' or 'update' | |
# Push the object to the external service via the service's synchronizer | |
synchronizer.push_data(crud_option, instance) | |
@receiver(post_delete, sender=SomeModel) | |
@receiver(post_save, sender=AnotherModel) | |
def remove_object_from_external_services(sender, instnace, **kwargs): | |
" Remove object from the appropriate external services. " | |
# .... logic to get all of the services this object needs to removed from .... | |
for external_service in external_services: | |
# Instantiate the ExternalService's Synchronizer | |
synchronizer = external_service.get_synchronizer() | |
# Set the `CRUD` option (either create or update) | |
crud_option = 'remove' | |
# Push the object to the external service via the service's synchronizer | |
synchronizer.push_data(crud_option, instance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment