Changes on server

- bugfixes in gcal callback
- requirements txt
This commit is contained in:
Martin Bauer
2014-04-21 09:21:59 +02:00
parent aac687c0c7
commit 46b4078fac
9 changed files with 84 additions and 56 deletions

View File

@@ -282,10 +282,10 @@ def checkGCalSubscription():
global service
callbackUrl = settings.GCAL_COUPLING['push_url']
#timeToLive = 14*24*3600 # how long the channel should be active
#renewBeforeExpiry = 2*24*3600 # duration before expiry when channel is renewed
timeToLive = 60*5
renewBeforeExpiry = 60*3
timeToLive = 14*24*3600 # how long the channel should be active
renewBeforeExpiry = 2*24*3600 # duration before expiry when channel is renewed
#timeToLive = 60*5
#renewBeforeExpiry = 60*3
# Test if a channel already exists for this callbackURL
try:
@@ -318,4 +318,4 @@ def checkGCalSubscription():
def stopAllGCalSubscriptions():
for dbChannel in GCalPushChannel.objects.all():
print("Stopping %s expiry at %d " % ( dbChannel.id, dbChannel.expiration ) )
GCalPushChannel.stop( service, dbChannel.toGChannel() )
GCalPushChannel.stop( service, dbChannel.toGChannel() )

View File

@@ -2,9 +2,11 @@ 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
import eventplanner_gcal.models
import logging
logger = logging.getLogger( __name__ )
class SignalLock:
def __init__(self):
@@ -25,10 +27,21 @@ class SignalLock:
signalLock = SignalLock()
@receiver( post_save, sender=User )
def user_changed( **kwargs ):
def onGoogleCallback():
if not signalLock.isLocked():
with signalLock:
logger.info( "Sync back from google" )
eventplanner_gcal.models.syncParticipationFromGoogleToLocal()
@receiver( post_save, sender=User )
def user_changed( **kwargs ):
logger.info("User info changed")
if not signalLock.isLocked():
with signalLock:
logger.info("Synchronizing with google - user information changed")
eventplanner_gcal.models.deleteAllGCalEvents()
eventplanner_gcal.models.syncGCalEvents()
@@ -39,10 +52,10 @@ def event_post_save_handler( **kwargs):
event = kwargs['instance']
created = kwargs['created']
if created:
print("Creating Gcal event")
logger.info("Creating Gcal event")
eventplanner_gcal.models.createGCalEvent( event ).execute()
else:
print( "Updating Gcal event")
logger.info( "Updating Gcal event")
eventplanner_gcal.models.updateGCalEvent( event ).execute()
@@ -52,7 +65,7 @@ def event_pre_delete_handler( **kwargs):
if not signalLock.isLocked():
with signalLock:
event = kwargs['instance']
print ("Deleting GCAL event")
logger.info ("Deleting GCAL event")
eventplanner_gcal.models.deleteGCalEvent( event ).execute()
@@ -61,7 +74,7 @@ def participation_post_save_handler( **kwargs):
if not signalLock.isLocked():
with signalLock:
participation = kwargs['instance']
print("Participation post save -> update gcal")
logger.info("Participation post save -> update gcal")
eventplanner_gcal.models.updateGCalEvent( participation.event ).execute()

View File

@@ -1,16 +1,24 @@
from django.shortcuts import redirect
from eventplanner_gcal.models import syncGCalEvents, syncParticipationFromGoogleToLocal
from eventplanner_gcal.signals import onGoogleCallback
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import logging
logger = logging.getLogger( __name__ )
def runSync( request ):
syncGCalEvents()
return redirect("/")
@csrf_exempt
def gcalApiCallback( request ):
syncParticipationFromGoogleToLocal()
print ( "gcalApiCallback called" )
return redirect("/")
onGoogleCallback()
logger.info("Received callback from GCal - updating event participations... ")
return HttpResponse('<h1>Callback successful</h1>')