Bugfixes in Eventplanning & gcal coupling module

This commit is contained in:
Martin Bauer
2014-06-22 11:52:26 +02:00
parent df22b838fa
commit 568376fbe7
4 changed files with 41 additions and 23 deletions

View File

@@ -58,18 +58,27 @@ def buildGCalAttendeesObj( event ):
for userMapping in UserGCalCoupling.objects.all():
u = userMapping.user
participation = EventParticipation.get_or_create( u, event )
# No get or create here, since a create would trigger another synchronization
#participation = EventParticipation.get_or_create( u, event )
try:
participation = EventParticipation.objects.get( event = event, user = u )
localStatus = participation.status
localComment = participation.comment
except EventParticipation.DoesNotExist:
localStatus = "-"
localComment = ""
status = "needsAction"
if participation.status == "?" : status = "tentative"
if participation.status == 'Yes': status = "accepted"
if participation.status == 'No' : status = "declined"
if localStatus == "?" : status = "tentative"
if localStatus == 'Yes': status = "accepted"
if localStatus == 'No' : status = "declined"
o = {
'id': userMapping.email,
'email': userMapping.email,
'displayName': u.username,
'comment': participation.comment,
'comment': localComment,
'responseStatus': status,
}
result.append( o )
@@ -115,6 +124,18 @@ def buildGCalEvent( event, timezone="Europe/Berlin" ):
}
# ------------------------------ Callback Functions ------------------------------------------------
def onGcalEventCreated( request_id, response, exception=None ):
"""Callback function for created events to enter new gcal id in the mapping table"""
if exception is not None:
print ( "response " + str( response ) )
raise exception
googleId = response['id']
djangoId = response['extendedProperties']['private']['blechreizID']
mapping = GCalMapping( gcal_id = googleId, event = Event.objects.get( pk=djangoId ) )
mapping.save()
# ------------------------------ GCal Api Calls -------------------------------------------------
@@ -142,19 +163,23 @@ def getAllGCalEvents( service, fromNow=False ):
def createGCalEvent( service, event, timezone="Europe/Berlin" ):
"""Creates a new gcal event using a local event"""
googleEvent = buildGCalEvent(event,timezone)
return service.events().insert(calendarId='primary', body=googleEvent)
return service.events().insert(calendarId='primary', body=googleEvent )
def updateGCalEvent( service, event, timezone="Europe/Berlin"):
"""Updates an existing gcal event, using a local event"""
googleEvent = buildGCalEvent(event,timezone)
mapping = GCalMapping.objects.get( event=event )
gcalId = mapping.gcal_id
return service.events().patch(calendarId='primary', eventId= gcalId, body=googleEvent)
try:
mapping = GCalMapping.objects.get( event=event )
except GCalMapping.DoesNotExist:
return createGCalEvent( service, event, timezone )
return service.events().patch(calendarId='primary', eventId= mapping.gcal_id, body=googleEvent)
def deleteGCalEvent( service, event ):
"""Deletes gcal that belongs to the given local event"""
mapping = GCalMapping.objects.get( event=event )
gcalId = mapping.gcal_id
mapping.delete()
return service.events().delete(calendarId='primary', eventId=gcalId)
@@ -176,6 +201,8 @@ def deleteAllGCalEvents( service = getServiceObject() ):
batch.add( service.events().delete(calendarId='primary', eventId=id) )
batch.execute()
GCalMapping.objects.all().delete()
return l
def syncFromLocalToGoogle( service = None ):
@@ -198,16 +225,7 @@ def syncFromLocalToGoogle( service = None ):
eventsToCreate_djangoID = localEvents_djangoID - eventsAtGoogle_djangoID
eventsToDelete_googleID = eventsAtGoogle_googleID - localEvents_googleID
def onGcalEventCreated( request_id, response, exception ):
"""Callback function for created events to enter new gcal id in the mapping table"""
if exception is not None:
print ( "response " + str( response ) )
raise exception
googleId = response['id']
djangoId = response['extendedProperties']['private']['blechreizID']
mapping = GCalMapping( gcal_id = googleId, event = Event.objects.get( pk=djangoId ) )
mapping.save()