Ejemplo n.º 1
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')
Ejemplo n.º 2
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')
Ejemplo 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')
Ejemplo 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')
Ejemplo n.º 5
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')
Ejemplo n.º 6
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 ''
Ejemplo n.º 7
0
def get_favorites_contributions(contributions, user_id):
    contribs_in_db = []
    for contribution in contributions:
        if 'conferenceId' in contribution:
            if db_event.get_favorites_event(user_id, contribution['conferenceId']):
                contribs_in_db.append(contribution)
            if 'slot' in contribution:
                if contribution['slot']:
                    session = contribution['slot']
                    if db_session.get_favorites_session(user_id, contribution['conferenceId'], session['sessionId']):
                        contribs_in_db.append(contribution)
            if db_contribution.get_favorites_contribution(user_id, contribution['conferenceId'], contribution['contributionId']):
                contribs_in_db.append(contribution)
        else:
            if db_event.get_favorites_event(user_id, contribution['id']):
                contribs_in_db.append(contribution)
    return contribs_in_db
Ejemplo n.º 8
0
def get_favorites_history():
    user_id = flask_session['indico_user']
    events = []
    event_ids = db_event.get_history(user_id, order=-1)
    for event in event_ids:
        eventInHistory = db_event.get_favorites_event(user_id, event['id'])
        if eventInHistory:
            events.append(eventInHistory['event'])
    return Response(json.dumps(events), mimetype='application/json')
Ejemplo n.º 9
0
def get_favorites_event_sessions(event_id):
    user_id = flask_session['indico_user']
    sessions = event_logic.get_event_sessions(event_id)
    sessions_in_db = []
    for session in sessions:
        if db_event.get_favorites_event(user_id, session['conferenceId']):
            sessions_in_db.append(session)
        elif db_session.get_favorites_session(user_id, session['conferenceId'], session['sessionId']):
            sessions_in_db.append(session)
    return Response(json.dumps(sessions_in_db), mimetype='application/json')
Ejemplo n.º 10
0
def get_favorites_event_sessions(event_id):
    user_id = flask_session['indico_user']
    sessions = event_logic.get_event_sessions(event_id)
    sessions_in_db = []
    for session in sessions:
        if db_event.get_favorites_event(user_id, session['conferenceId']):
            sessions_in_db.append(session)
        elif db_session.get_favorites_session(user_id, session['conferenceId'],
                                              session['sessionId']):
            sessions_in_db.append(session)
    return Response(json.dumps(sessions_in_db), mimetype='application/json')
Ejemplo n.º 11
0
def add_event(event_id):
    user_id = flask_session['indico_user']
    event_logic.update_event_info(event_id)
    event = db_event.get_event(event_id)
    if db_event.get_favorites_event(user_id, event_id):
        print 'already in favorites'
    else:
        db_contribution.remove_event_contributions_from_favorites(user_id, event_id)
        db_session.remove_event_sessions_from_favorites(user_id, event_id)
        db_event.add_event_to_favorites(user_id, event)
    return ''
Ejemplo n.º 12
0
def add_event(event_id):
    user_id = flask_session['indico_user']
    event_logic.update_event_info(event_id)
    event = db_event.get_event(event_id)
    if db_event.get_favorites_event(user_id, event_id):
        print 'already in favorites'
    else:
        db_contribution.remove_event_contributions_from_favorites(
            user_id, event_id)
        db_session.remove_event_sessions_from_favorites(user_id, event_id)
        db_event.add_event_to_favorites(user_id, event)
    return ''
Ejemplo 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')
Ejemplo n.º 14
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')
Ejemplo n.º 15
0
def remove_contribution(event_id, contribution_id):
    user_id = flask_session['indico_user']
    favorites_contribution = db_contribution.get_favorites_contribution(user_id, event_id, contribution_id)
    contribution_db = db_contribution.get_contribution(event_id, contribution_id)
    session_id = None
    if contribution_db['slot']:
        session_id = contribution_db['slot']['sessionId']
    if favorites_contribution:
        db_contribution.remove_contribution_from_favorites(user_id, event_id, contribution_id)
    elif db_event.get_favorites_event(user_id, event_id):
        db_event.remove_event_from_favorites(user_id, event_id)
        contributions = db_contribution.get_event_contributions(event_id, {'contributionId': {'$ne': contribution_id}})
        for contribution in contributions:
            add_contribution(event_id, contribution['contributionId'])
    elif session_id:
        if  db_contribution.get_favorites_contribution(user_id, event_id, session_id):
            contributions = db_contribution.get_event_contributions(event_id, {'slot':{'$ne': None}, 'contributionId': {'$ne': contribution_id}}, True)
            db_session.remove_session_from_favorites(user_id, event_id, session_id)
            for contribution in contributions:
                if contribution['slot']['sessionId'] == session_id:
                    add_contribution(event_id, contribution['contributionId'])
    return ''
Ejemplo n.º 16
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')
Ejemplo n.º 17
0
def remove_contribution(event_id, contribution_id):
    user_id = flask_session['indico_user']
    favorites_contribution = db_contribution.get_favorites_contribution(
        user_id, event_id, contribution_id)
    contribution_db = db_contribution.get_contribution(event_id,
                                                       contribution_id)
    session_id = None
    if contribution_db['slot']:
        session_id = contribution_db['slot']['sessionId']
    if favorites_contribution:
        db_contribution.remove_contribution_from_favorites(
            user_id, event_id, contribution_id)
    elif db_event.get_favorites_event(user_id, event_id):
        db_event.remove_event_from_favorites(user_id, event_id)
        contributions = db_contribution.get_event_contributions(
            event_id, {'contributionId': {
                '$ne': contribution_id
            }})
        for contribution in contributions:
            add_contribution(event_id, contribution['contributionId'])
    elif session_id:
        if db_contribution.get_favorites_contribution(user_id, event_id,
                                                      session_id):
            contributions = db_contribution.get_event_contributions(
                event_id, {
                    'slot': {
                        '$ne': None
                    },
                    'contributionId': {
                        '$ne': contribution_id
                    }
                }, True)
            db_session.remove_session_from_favorites(user_id, event_id,
                                                     session_id)
            for contribution in contributions:
                if contribution['slot']['sessionId'] == session_id:
                    add_contribution(event_id, contribution['contributionId'])
    return ''
Ejemplo n.º 18
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 ''
Ejemplo n.º 19
0
def get_favorites_events(events, user_id):
    events_in_db = []
    for event in events:
        if db_event.get_favorites_event(user_id, event["id"]):
            events_in_db.append(event)
    return events_in_db