GCal Coupling: Management Site - decoupled Email from profile

This commit is contained in:
Martin Bauer
2014-06-20 12:24:01 +02:00
parent 6431764858
commit 290db91956
16 changed files with 410 additions and 29 deletions

View File

@@ -4,11 +4,12 @@ import datetime
import time
from eventplanner.models import Event, EventParticipation
from eventplanner_gcal.models import GCalMapping, GCalPushChannel
from eventplanner_gcal.models import GCalMapping, GCalPushChannel,UserGCalCoupling
from apiclient.http import BatchHttpRequest
from django.contrib.auth.models import User
from django.conf import settings
from pprint import pprint
logger = logging.getLogger(__name__)
@@ -54,21 +55,22 @@ def buildGCalAttendeesObj( event ):
"""Builds a attendees object that is inserted into the GCal event.
Attendees are all users that have a google mail address. """
result = []
for u in User.objects.all():
if u.email.endswith( "@gmail.com") or u.email.endswith("@googlemail.com"):
participation = EventParticipation.get_or_create( u, event )
status = "tentative"
if participation.status == 'Yes': status = "accepted"
if participation.status == 'No' : status = "declined"
o = {
'id': u.email,
'email': u.email,
'displayName': u.username,
'comment': participation.comment,
'responseStatus': status,
}
result.append( o )
for userMapping in UserGCalCoupling.objects.all():
u = userMapping.user
participation = EventParticipation.get_or_create( u, event )
status = "tentative"
if participation.status == 'Yes': status = "accepted"
if participation.status == 'No' : status = "declined"
o = {
'id': userMapping.email,
'email': u.email,
'displayName': u.username,
'comment': participation.comment,
'responseStatus': status,
}
result.append( o )
return result
@@ -222,6 +224,9 @@ def syncFromLocalToGoogle( service = None ):
eventDjangoID = int( gcalEv['extendedProperties']['private']['blechreizID'] )
try:
djangoEv = Event.objects.get( pk=eventDjangoID )
if 'attendees' not in gcalEv:
gcalEv['attendees'] = []
if gcalEv['attendees'] != buildGCalAttendeesObj( djangoEv ):
batch.add( updateGCalEvent( service, djangoEv ) )
batchIsEmpty = False