Esempio n. 1
0
def get_favorites_event_days_session(event_id, session_id):
    user_id = flask_session['indico_user']
    event_in_db = db_event.get_favorites_event(user_id, event_id)
    session_in_db = db_session.get_favorites_session(user_id, event_id,
                                                     session_id)
    if event_in_db:
        return Response(json.dumps(
            event_logic.get_event_same_sessions(event_id, session_id)),
                        mimetype='application/json')
    elif session_in_db:
        return Response(json.dumps(
            event_logic.get_event_same_sessions(event_id, session_id)),
                        mimetype='application/json')
    else:
        sessions = []
        contributions_in_db = db_contribution.get_favorites_event_contributions(
            user_id, event_id, True)
        for contribution in contributions_in_db:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                session = current_contribution['slot']
                if not session in sessions and session[
                        'sessionId'] == session_id:
                    sessions.append(session)
        return Response(json.dumps(
            sorted(sessions, key=lambda x: x['startDate'])),
                        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 remove_session(event_id, session_id):
    user_id = flask_session['indico_user']
    eventInFavorites = db_event.get_favorites_event(user_id, event_id)
    sessionInFavorites = db_session.get_favorites_session(
        user_id, event_id, session_id)
    if eventInFavorites:
        db_event.remove_event_from_favorites(user_id, event_id)
        session_ids = db_session.get_event_sessions(event_id)
        for current_id in session_ids:
            if current_id != session_id:
                session_slot = db_session.get_event_session(
                    event_id, current_id)
                if session_slot:
                    db_session.add_session_to_favorites(user_id, session_slot)
    elif sessionInFavorites:
        db_session.remove_session_from_favorites(user_id, event_id, session_id)
    else:
        contributions = db_contribution.get_favorites_event_contributions(
            user_id, event_id, True)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                current_slot = current_contribution['slot']
                if current_slot['sessionId'] == session_id:
                    remove_contribution(event_id,
                                        current_contribution['contributionId'])
    return ''
Esempio n. 5
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. 6
0
def add_contribution(event_id, contribution_id):
    user_id = flask_session['indico_user']
    if contribution_id:
        if db_contribution.get_favorites_contribution(user_id, event_id, contribution_id):
            print 'already in favorites'
        else:
            favorites_contribution = db_contribution.get_contribution(event_id, contribution_id)
            if favorites_contribution['slot']:
                session_id = favorites_contribution['slot']['sessionId']
                favorites_contributions = db_contribution.get_favorites_event_contributions(user_id, event_id, True)
                num_contrib_in_session_favorites = 0
                num_contrib_in_session_db = 0
                for contribution in favorites_contributions:
                    current_contribution = contribution['contribution']
                    if current_contribution['slot']:
                        if current_contribution['slot']['sessionId'] == session_id:
                            num_contrib_in_session_favorites += 1
                sessions_in_db = db_session.get_event_same_sessions(event_id, session_id)
                for session in sessions_in_db:
                    num_contrib_in_session_db += len(session['entries'])
                if num_contrib_in_session_db - num_contrib_in_session_favorites == 1:
                    add_session(event_id, session_id)
                else:
                    db_contribution.add_contribution_to_favorites(user_id, favorites_contribution)
            else:
                num_contrib_in_event = len(db_contribution.get_event_contributions(event_id, {'contributionId': {'$ne': None}}, False, False))
                num_contrib_in_favorites = db_contribution.get_num_favorites_event_contributions(user_id, event_id)
                if num_contrib_in_event - num_contrib_in_favorites == 1:
                    add_event(event_id)
                else:
                    db_contribution.add_contribution_to_favorites(user_id, favorites_contribution)
    return ''
Esempio n. 7
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. 8
0
def add_session(event_id, session_id):
    user_id = flask_session['indico_user']
    favorites_sessions = db_session.get_favorites_event_sessions(user_id, event_id)
    event_sessions = db_session.get_event_sessions(event_id)
    session = db_session.get_event_session(event_id, session_id)
    if len(event_sessions)-favorites_sessions.count() == 1:
        add_event(event_id)
    elif db_session.get_favorites_session(user_id, event_id, session_id):
        print 'already in favorites'
    else:
        contributions = db_contribution.get_favorites_event_contributions(user_id, event_id, True)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                if current_contribution['slot']['sessionId'] == session_id:
                    db_contribution.remove_contribution_from_favorites(user_id, event_id, current_contribution['contributionId'])
        db_session.add_session_to_favorites(user_id, session)
    return ''
Esempio n. 9
0
def get_favorites_event_days_session(event_id, session_id):
    user_id = flask_session['indico_user']
    event_in_db = db_event.get_favorites_event(user_id, event_id)
    session_in_db = db_session.get_favorites_session(user_id, event_id, session_id)
    if event_in_db:
        return Response(json.dumps(event_logic.get_event_same_sessions(event_id, session_id)), mimetype='application/json')
    elif session_in_db:
        return Response(json.dumps(event_logic.get_event_same_sessions(event_id, session_id)), mimetype='application/json')
    else:
        sessions = []
        contributions_in_db = db_contribution.get_favorites_event_contributions(user_id, event_id, True)
        for contribution in contributions_in_db:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                session = current_contribution['slot']
                if not session in sessions and session['sessionId'] == session_id:
                    sessions.append(session)
        return Response(json.dumps(sorted(sessions, key=lambda x:x['startDate'])), mimetype='application/json')
Esempio n. 10
0
def get_favorites_event_all_sessions(event_id):
    user_id = flask_session['indico_user']
    event_in_db = db_event.get_favorites_event(user_id, event_id)
    sessions = []
    if event_in_db:
        return Response(json.dumps(event_logic.get_event_sessions(event_id)), mimetype='application/json')
    else:
        sessions_in_db = db_session.get_favorites_event_sessions(user_id, event_id)
        for session in sessions_in_db:
            sessions.append(session['session_slot'])
        contributions_in_db = db_contribution.get_favorites_event_contributions(user_id, event_id)
        for contribution in contributions_in_db:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                session = current_contribution['slot']
                if not session in sessions:
                    sessions.append(session)
        return Response(json.dumps(sorted(sessions, key=lambda x:x['title'])), mimetype='application/json')
Esempio n. 11
0
def add_contribution(event_id, contribution_id):
    user_id = flask_session['indico_user']
    if contribution_id:
        if db_contribution.get_favorites_contribution(user_id, event_id,
                                                      contribution_id):
            print 'already in favorites'
        else:
            favorites_contribution = db_contribution.get_contribution(
                event_id, contribution_id)
            if favorites_contribution['slot']:
                session_id = favorites_contribution['slot']['sessionId']
                favorites_contributions = db_contribution.get_favorites_event_contributions(
                    user_id, event_id, True)
                num_contrib_in_session_favorites = 0
                num_contrib_in_session_db = 0
                for contribution in favorites_contributions:
                    current_contribution = contribution['contribution']
                    if current_contribution['slot']:
                        if current_contribution['slot'][
                                'sessionId'] == session_id:
                            num_contrib_in_session_favorites += 1
                sessions_in_db = db_session.get_event_same_sessions(
                    event_id, session_id)
                for session in sessions_in_db:
                    num_contrib_in_session_db += len(session['entries'])
                if num_contrib_in_session_db - num_contrib_in_session_favorites == 1:
                    add_session(event_id, session_id)
                else:
                    db_contribution.add_contribution_to_favorites(
                        user_id, favorites_contribution)
            else:
                num_contrib_in_event = len(
                    db_contribution.get_event_contributions(
                        event_id, {'contributionId': {
                            '$ne': None
                        }}, False, False))
                num_contrib_in_favorites = db_contribution.get_num_favorites_event_contributions(
                    user_id, event_id)
                if num_contrib_in_event - num_contrib_in_favorites == 1:
                    add_event(event_id)
                else:
                    db_contribution.add_contribution_to_favorites(
                        user_id, favorites_contribution)
    return ''
Esempio n. 12
0
def add_session(event_id, session_id):
    user_id = flask_session['indico_user']
    favorites_sessions = db_session.get_favorites_event_sessions(
        user_id, event_id)
    event_sessions = db_session.get_event_sessions(event_id)
    session = db_session.get_event_session(event_id, session_id)
    if len(event_sessions) - favorites_sessions.count() == 1:
        add_event(event_id)
    elif db_session.get_favorites_session(user_id, event_id, session_id):
        print 'already in favorites'
    else:
        contributions = db_contribution.get_favorites_event_contributions(
            user_id, event_id, True)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                if current_contribution['slot']['sessionId'] == session_id:
                    db_contribution.remove_contribution_from_favorites(
                        user_id, event_id,
                        current_contribution['contributionId'])
        db_session.add_session_to_favorites(user_id, session)
    return ''
Esempio n. 13
0
def get_favorites_event_all_sessions(event_id):
    user_id = flask_session['indico_user']
    event_in_db = db_event.get_favorites_event(user_id, event_id)
    sessions = []
    if event_in_db:
        return Response(json.dumps(event_logic.get_event_sessions(event_id)),
                        mimetype='application/json')
    else:
        sessions_in_db = db_session.get_favorites_event_sessions(
            user_id, event_id)
        for session in sessions_in_db:
            sessions.append(session['session_slot'])
        contributions_in_db = db_contribution.get_favorites_event_contributions(
            user_id, event_id)
        for contribution in contributions_in_db:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                session = current_contribution['slot']
                if not session in sessions:
                    sessions.append(session)
        return Response(json.dumps(sorted(sessions, key=lambda x: x['title'])),
                        mimetype='application/json')
Esempio n. 14
0
def remove_session(event_id, session_id):
    user_id = flask_session['indico_user']
    eventInFavorites = db_event.get_favorites_event(user_id, event_id)
    sessionInFavorites = db_session.get_favorites_session(user_id, event_id, session_id)
    if eventInFavorites:
        db_event.remove_event_from_favorites(user_id, event_id)
        session_ids = db_session.get_event_sessions(event_id)
        for current_id in session_ids:
            if current_id != session_id:
                session_slot = db_session.get_event_session(event_id, current_id)
                if session_slot:
                    db_session.add_session_to_favorites(user_id, session_slot)
    elif sessionInFavorites:
        db_session.remove_session_from_favorites(user_id, event_id, session_id)
    else:
        contributions = db_contribution.get_favorites_event_contributions(user_id, event_id, True)
        for contribution in contributions:
            current_contribution = contribution['contribution']
            if current_contribution['slot']:
                current_slot = current_contribution['slot']
                if current_slot['sessionId'] == session_id:
                    remove_contribution(event_id, current_contribution['contributionId'])
    return ''