Пример #1
0
def get_favorites_next_event():
    user_id = flask_session['indico_user']
    events = []
    now = datetime.utcnow()
    favorites_events = db_event.get_favorites_events(user_id)
    favorites_sessions = db_session.get_favorites_sessions(user_id)
    favorites_contributions = db_contribution.get_favorites_contributions(
        user_id)
    for event in favorites_events:
        current_event = event['event']
        if current_event['type'] == 'simple_event':
            if current_event['startDate'] > now:
                events.append(current_event)
        else:
            contributions = db_contribution.get_event_contributions(
                current_event['id'], {'startDate': {
                    '$gte': now
                }}, False, True)
            if contributions:
                events.append(current_event)
    for session in favorites_sessions:
        current_session = session['session_slot']
        session_slots = db_session.get_event_session_slots(
            current_session['conferenceId'], current_session['sessionId'],
            True)
        for session_slot in session_slots:
            contributions = []
            for contribution in session_slot['entries']:
                if contribution['startDate'] > now:
                    contributions.append(contribution["event"])
            if len(contributions) > 0:
                events.append(
                    sorted(contributions, key=lambda x: x['startDate'])[0])
    contributions = []
    for contribution in favorites_contributions:
        current_contribution = contribution['contribution']
        if current_contribution['startDate'] > now:
            contributions.append(current_contribution["event"])
    if len(contributions) > 0:
        contributions = sorted(contributions, key=lambda x: x['startDate'])
        events.append(contributions[0]["event"])
    nextEvent = []
    if len(events) > 0:
        nextEvent = sorted(events, key=lambda x: x['startDate'])[0]
    return Response(json.dumps(nextEvent), mimetype='application/json')
Пример #2
0
def my_favorites_events():
    user_id = flask_session['indico_user']
    events = []
    contributions = db_contribution.get_favorites_contributions(user_id, distinct=True)
    for event_id in contributions:
        event = db_event.get_event(event_id)
        if not event in events:
            events.append(event)
    sessions = db_session.get_favorites_sessions(user_id, distinct=True)
    for event_id in sessions:
        event = db_event.get_event(event_id)
        if not event in events:
            events.append(event)
    events_in_db = db_event.get_favorites_events(user_id)
    for event in events_in_db:
        events.append(event['event'])
    events = sorted(events, key=lambda x:x['startDate'])
    events.reverse()
    return Response(json.dumps(events), mimetype='application/json')
Пример #3
0
def my_favorites_events():
    user_id = flask_session['indico_user']
    events = []
    contributions = db_contribution.get_favorites_contributions(user_id,
                                                                distinct=True)
    for event_id in contributions:
        event = db_event.get_event(event_id)
        if not event in events:
            events.append(event)
    sessions = db_session.get_favorites_sessions(user_id, distinct=True)
    for event_id in sessions:
        event = db_event.get_event(event_id)
        if not event in events:
            events.append(event)
    events_in_db = db_event.get_favorites_events(user_id)
    for event in events_in_db:
        events.append(event['event'])
    events = sorted(events, key=lambda x: x['startDate'])
    events.reverse()
    return Response(json.dumps(events), mimetype='application/json')
Пример #4
0
def get_favorites_next_event():
    user_id = flask_session['indico_user']
    events = []
    now = datetime.utcnow()
    favorites_events = db_event.get_favorites_events(user_id)
    favorites_sessions = db_session.get_favorites_sessions(user_id)
    favorites_contributions = db_contribution.get_favorites_contributions(user_id)
    for event in favorites_events:
        current_event = event['event']
        if current_event['type'] == 'simple_event':
            if current_event['startDate'] > now:
                events.append(current_event)
        else:
            contributions = db_contribution.get_event_contributions(current_event['id'], {'startDate': {'$gte': now}}, False, True)
            if contributions:
                events.append(contributions[0])
    for session in favorites_sessions:
        current_session = session['session_slot']
        session_slots = db_session.get_event_session_slots(current_session['conferenceId'], current_session['sessionId'], True)
        for session_slot in session_slots:
            contributions = []
            for contribution in session_slot['entries']:
                if contribution['startDate'] > now:
                    contributions.append(contribution)
            if len(contributions) > 0:
                events.append(sorted(contributions, key=lambda x:x['startDate'])[0])
    contributions = []
    for contribution in favorites_contributions:
        current_contribution = contribution['contribution']
        if current_contribution['startDate'] > now:
            contributions.append(current_contribution)
    if len(contributions) > 0:
        contributions = sorted(contributions, key=lambda x:x['startDate'])
        events.append(contributions[0])
    nextEvent = []
    if len(events) > 0:
        nextEvent = sorted(events, key=lambda x:x['startDate'])[0]
    return Response(json.dumps(nextEvent), mimetype='application/json')