def handle_calendar_updates(namespace_id, calendars, log, db_session):
 ids_ = []
 added_count = 0
 updated_count = 0
 for calendar in calendars:
  assert (calendar.uid is not None), 'Got remote item with null uid'
  local_calendar = db_session.query(Calendar).filter((Calendar.namespace_id == namespace_id), (Calendar.uid == calendar.uid)).first()
  if (local_calendar is not None):
   local_calendar.update(calendar)
   updated_count += 1
  else:
   local_calendar = Calendar(namespace_id=namespace_id)
   local_calendar.update(calendar)
   db_session.add(local_calendar)
   added_count += 1
  db_session.commit()
  ids_.append((local_calendar.uid, local_calendar.id))
 log.info('synced added and updated calendars', added=added_count, updated=updated_count)
 return ids_

def handle_calendar_updates ( namespace_id , calendars , log , db_session ) : ids_ = [ ] added_count = 0 updated_count = 0 for calendar in calendars : assert ( calendar . uid is not None ) , 'Got remote item with null uid' local_calendar = db_session . query ( Calendar ) . filter ( ( Calendar . namespace_id == namespace_id ) , ( Calendar . uid == calendar . uid ) ) . first ( ) if ( local_calendar is not None ) : local_calendar . update ( calendar ) updated_count += 1 else : local_calendar = Calendar ( namespace_id = namespace_id ) local_calendar . update ( calendar ) db_session . add ( local_calendar ) added_count += 1 db_session . commit ( ) ids_ . append ( ( local_calendar . uid , local_calendar . id ) ) log . info ( 'synced added and updated calendars' , added = added_count , updated = updated_count ) return ids_
persists new or updated calendar objects to the database .