Esempio n. 1
0
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()
Esempio n. 2
0
 def _apply_changes(self, sender, **kwargs):
     # we are using after_request to avoid unnecessary db deletes+inserts for the same entry since
     # especially event_data_changes is often triggered more than once e.g. for most date changes
     if 'outlook_changes' not in g:
         return
     user_events = defaultdict(list)
     for event, user, action in g.outlook_changes:
         user_events[(user, event)].append(action)
     for (user, event), data in user_events.viewitems():
         for action in latest_actions_only(data):
             OutlookQueueEntry.record(event, user, action)