from django.db.models.signals import post_save,pre_delete from django.dispatch import receiver from eventplanner.models import Event, EventParticipation from django.contrib.auth.models import User from eventplanner_gcal.google_sync import getServiceObject, syncFromLocalToGoogle,\ createGCalEvent, deleteGCalEvent, updateGCalEvent, onGcalEventCreated import logging logger = logging.getLogger( __name__ ) #@receiver( post_save, sender=User ) #def user_changed( **kwargs ): # logger.info("Synchronizing with google - user information changed") # syncFromLocalToGoogle( getServiceObject() ) @receiver( post_save,sender= Event) def event_post_save_handler( **kwargs): event = kwargs['instance'] created = kwargs['created'] if created: logger.info("Creating Gcal event") response = createGCalEvent( getServiceObject(), event ).execute() onGcalEventCreated( None, response, None ) else: logger.info( "Updating Gcal event") updateGCalEvent( getServiceObject(),event ).execute() @receiver( pre_delete,sender= Event) def event_pre_delete_handler( **kwargs): event = kwargs['instance'] logger.info ("Deleting GCAL event") deleteGCalEvent( getServiceObject(), event ).execute() @receiver( post_save, sender=EventParticipation ) def participation_post_save_handler( **kwargs): participation = kwargs['instance'] logger.info("Participation post save -> update gcal") updateGCalEvent( getServiceObject(), participation.event ).execute()