Esempio n. 1
0
def get_favorites_event_speakers(event_id):
    user_id = flask_session['indico_user']
    if db_event.get_favorites_event(user_id, event_id):
        return Response(json.dumps(
            event_logic.get_event_speakers(event_id,
                                           int(request.args.get('page', 1)))),
                        mimetype='application/json')
    else:
        speakers = []
        favorites_sessions = db_session.get_favorites_event_sessions(
            user_id, event_id)
        contribs = []
        for session in favorites_sessions:
            current_session = session['session_slot']
            for slot in db_session.get_event_session_slots(
                    event_id, current_session['sessionId'], True):
                for contrib in slot['entries']:
                    contribs.append(contrib)
        contributions = db_contribution.get_favorites_event_contributions(
            user_id, event_id)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            for speaker in current_contribution['presenters']:
                if not speaker in speakers:
                    speakers.append(speaker)
        for contribution in contribs:
            for speaker in contribution['presenters']:
                if not speaker in speakers:
                    speakers.append(speaker)

        return Response(json.dumps(sorted(speakers, key=lambda x: x['name'])),
                        mimetype='application/json')
Esempio n. 2
0
def get_favorites_event_days(event_id):
    user_id = flask_session['indico_user']
    if db_event.get_favorites_event(user_id, event_id):
        return Response(json.dumps(list(db_event.get_event_days(event_id))),
                        mimetype='application/json')
    else:
        days = []
        favorites_sessions = db_session.get_favorites_event_sessions(
            user_id, event_id)
        sessions = []
        for session in favorites_sessions:
            current_session = session['session_slot']
            for slot in db_session.get_event_session_slots(
                    event_id, current_session['sessionId'], False):
                sessions.append(slot)
        contributions = db_contribution.get_favorites_event_contributions(
            user_id, event_id)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            date = current_contribution['startDate'].strftime('%Y-%m-%d')
            if not date in days:
                days.append(date)
        for session in sessions:
            date = session['startDate'].strftime('%Y-%m-%d')
            if not date in days:
                days.append(date)
        results = []
        for day in days:
            results.append(db_event.create_event_day(event_id, day))
        return Response(json.dumps(sorted(results, key=lambda x: x['date'])),
                        mimetype='application/json')
Esempio n. 3
0
def get_favorites_event_speakers(event_id):
    user_id = flask_session['indico_user']
    if db_event.get_favorites_event(user_id, event_id):
        return Response(json.dumps(event_logic.get_event_speakers(event_id, int(request.args.get('page', 1)))), mimetype='application/json')
    else:
        speakers = []
        favorites_sessions = db_session.get_favorites_event_sessions(user_id, event_id)
        contribs = []
        for session in favorites_sessions:
            current_session = session['session_slot']
            for slot in db_session.get_event_session_slots(event_id, current_session['sessionId'], True):
                for contrib in slot['entries']:
                    contribs.append(contrib)
        contributions = db_contribution.get_favorites_event_contributions(user_id, event_id)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            for speaker in current_contribution['presenters']:
                if not speaker in speakers:
                    speakers.append(speaker)
        for contribution in contribs:
            for speaker in contribution['presenters']:
                if not speaker in speakers:
                    speakers.append(speaker)

        return Response(json.dumps(sorted(speakers, key=lambda x:x['name'])), mimetype='application/json')
Esempio n. 4
0
def get_favorites_event_days(event_id):
    user_id = flask_session['indico_user']
    if db_event.get_favorites_event(user_id, event_id):
        return Response(json.dumps(list(db_event.get_event_days(event_id))), mimetype='application/json')
    else:
        days = []
        favorites_sessions = db_session.get_favorites_event_sessions(user_id, event_id)
        sessions = []
        for session in favorites_sessions:
            current_session = session['session_slot']
            for slot in db_session.get_event_session_slots(event_id, current_session['sessionId'], False):
                sessions.append(slot)
        contributions = db_contribution.get_favorites_event_contributions(user_id, event_id)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            date = current_contribution['startDate'].strftime('%Y-%m-%d')
            if not date in days:
                days.append(date)
        for session in sessions:
            date = session['startDate'].strftime('%Y-%m-%d')
            if not date in days:
                days.append(date)
        results = []
        for day in days:
            results.append(db_event.create_event_day(event_id, day))
        return Response(json.dumps(sorted(results, key=lambda x:x['date'])), mimetype='application/json')
Esempio n. 5
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')
Esempio n. 6
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')