def update_calendar(): """Executes all pending calendar updates""" from indico_outlook.plugin import OutlookPlugin if not check_config(): OutlookPlugin.logger.error('Plugin is not configured properly') return settings = OutlookPlugin.settings.get_all() query = (OutlookQueueEntry.find(_eager=OutlookQueueEntry.event).order_by( OutlookQueueEntry.user_id, OutlookQueueEntry.id)) entries = MultiDict( ((entry.user_id, entry.event_id), entry) for entry in query) delete_ids = set() try: for (user_id, event_id), entry_list in entries.iterlists(): entry_ids = {x.id for x in entry_list} for entry in latest_actions_only(entry_list): if is_event_excluded(entry.event): continue if not _update_calendar_entry(entry, settings): entry_ids.remove(entry.id) # record all ids which didn't fail for deletion delete_ids |= entry_ids finally: if delete_ids: OutlookQueueEntry.find( OutlookQueueEntry.id.in_(delete_ids)).delete( synchronize_session=False) db.session.commit()
def _record_change(self, event, user, action): if is_event_excluded(event): return if 'outlook_changes' not in g: g.outlook_changes = [] g.outlook_changes.append((event, user, action))