2014-03-09 18:13:30 +01:00
|
|
|
from django.db.models.signals import post_save,pre_delete
|
|
|
|
from django.dispatch import receiver
|
2014-04-19 20:36:01 +02:00
|
|
|
from eventplanner.models import Event, EventParticipation
|
|
|
|
from django.contrib.auth.models import User
|
2014-04-26 11:17:10 +02:00
|
|
|
from eventplanner_gcal.google_sync import getServiceObject, syncFromLocalToGoogle,\
|
|
|
|
createGCalEvent, deleteGCalEvent, updateGCalEvent
|
2014-04-18 13:43:02 +02:00
|
|
|
|
2014-04-26 11:17:10 +02:00
|
|
|
import logging
|
2014-04-21 09:21:59 +02:00
|
|
|
logger = logging.getLogger( __name__ )
|
2014-04-18 13:43:02 +02:00
|
|
|
|
|
|
|
|
2014-04-19 20:36:01 +02:00
|
|
|
@receiver( post_save, sender=User )
|
|
|
|
def user_changed( **kwargs ):
|
2014-04-26 11:17:10 +02:00
|
|
|
logger.info("Synchronizing with google - user information changed")
|
|
|
|
syncFromLocalToGoogle( getServiceObject() )
|
2014-04-19 20:36:01 +02:00
|
|
|
|
2014-03-09 18:13:30 +01:00
|
|
|
|
|
|
|
@receiver( post_save,sender= Event)
|
2014-04-18 13:43:02 +02:00
|
|
|
def event_post_save_handler( **kwargs):
|
2014-04-26 11:17:10 +02:00
|
|
|
event = kwargs['instance']
|
|
|
|
created = kwargs['created']
|
|
|
|
if created:
|
|
|
|
logger.info("Creating Gcal event")
|
|
|
|
createGCalEvent( getServiceObject(), event ).execute()
|
|
|
|
else:
|
|
|
|
logger.info( "Updating Gcal event")
|
|
|
|
updateGCalEvent( getServiceObject(),event ).execute()
|
2014-03-09 18:13:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-18 13:43:02 +02:00
|
|
|
@receiver( pre_delete,sender= Event)
|
|
|
|
def event_pre_delete_handler( **kwargs):
|
2014-04-26 11:17:10 +02:00
|
|
|
event = kwargs['instance']
|
|
|
|
logger.info ("Deleting GCAL event")
|
|
|
|
deleteGCalEvent( getServiceObject(), event ).execute()
|
2014-03-09 18:13:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
@receiver( post_save, sender=EventParticipation )
|
2014-04-18 13:43:02 +02:00
|
|
|
def participation_post_save_handler( **kwargs):
|
2014-04-26 11:17:10 +02:00
|
|
|
participation = kwargs['instance']
|
|
|
|
logger.info("Participation post save -> update gcal")
|
|
|
|
updateGCalEvent( getServiceObject(), participation.event ).execute()
|