Beispiel #1
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 ''
Beispiel #2
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 ''
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 ''
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')
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 ''
Beispiel #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')