Esempio n. 1
0
def friends(id_user=None):
    if not 'id' in session and not id_user:
        return redirect('/')
    if 'id' in session:
        user = user_model.get_user_by_id(session.get('id'))[0]
        friends = sympathys.get_sympathys_list(session.get('id'))
        incoming_requests = sympathys.get_incoming_requests(session.get('id'))
        outgoing_requests = sympathys.get_outgoing_requests(session.get('id'))
        blocked_users = sympathys.get_blocked_users(session.get('id'))

    if id_user:
        if not user_model.get_user_by_id(id_user):
            return render_template('404.html')
        if sympathys.check_block(id_user, session.get('id')):
            return redirect('/profile/id' + str(id_user))
        user = user_model.get_user_by_id(id_user)[0]
        friends = sympathys.get_sympathys_list(id_user)
        incoming_requests = None
        outgoing_requests = None
        blocked_users = None

    data = {
        'user':
        user,
        'sympathys':
        sympathys,
        'friends':
        friends,
        'get_user_by_id':
        user_model.get_user_by_id,
        'incoming_requests':
        incoming_requests,
        'outgoing_requests':
        outgoing_requests,
        'unread_messages_nbr':
        messages_model.get_unread_messages_nbr_by_user_id(session.get('id')),
        'incoming_requests_nbr':
        sympathys.get_incoming_requests_nbr(session.get('id')),
        'blocked_users':
        blocked_users,
        'check_block':
        sympathys.check_block,
        'offline_users':
        get_offline_users(),
        'online_users':
        get_online_users()
    }
    return render_template('friends.html', data=data)
Esempio n. 2
0
def newsfeed():
    if 'id' in session:
        my_id = session.get('id')
        friends = sympathys.get_sympathys_list(my_id)
        photos = []
        if friends:
            for friend in friends:
                if friend['id_user1'] == my_id:
                    photos = photos_model.get_photos_by_id(friend['id_user2'])
                else:
                    photos = photos_model.get_photos_by_id(friend['id_user1'])
            if photos:
                photos = sorted(photos,
                                key=lambda k: k['date_added'],
                                reverse=True)
        data = {
            'user':
            user_model.get_user_by_id(my_id)[0],
            'get_user_by_id':
            user_model.get_user_by_id,
            'get_avatar':
            user_model.get_avatar,
            'unread_messages_nbr':
            messages_model.get_unread_messages_nbr_by_user_id(my_id),
            'incoming_requests_nbr':
            sympathys.get_incoming_requests_nbr(my_id),
            'check_like':
            likes.check_like,
            'check_dislike':
            likes.check_dislike,
            'photos':
            photos,
            'likes':
            likes.photo_likes,
            'dislikes':
            likes.photo_dislikes,
            'get_comments_by_photo_id':
            comments.get_comments_by_photo_id,
            'online_users':
            get_online_users(),
            'friends':
            sympathys.get_sympathys_list(session.get('id')),
        }
        return render_template('newsfeed.html', data=data)
    return redirect('/')
Esempio n. 3
0
def suggestions():
    if not 'id' in session:
        return redirect('/')
    user = user_model.get_user_by_id(session.get('id'))[0]
    selected = get_suggestions_for_user(user)
    suggestions = []
    for suggestion in selected:
        correct = True
        if sympathys.check_block(suggestion['id'], session.get('id')):
            correct = False
        geolocation = geolocation_model.get_geolocation_by_user_id(
            suggestion['id'])
        if geolocation:
            suggestion['latitude'] = float(geolocation['latitude'])
            suggestion['longitude'] = float(geolocation['longitude'])
        else:
            suggestion['latitude'] = None
            suggestion['longitude'] = None
        suggestion['distance'] = calculate_distance(suggestion['latitude'],
                                                    suggestion['longitude'])
        if suggestion['distance'] is None:
            correct = False
        my_interests = user_model.get_interests_by_user_id(session.get('id'))
        suggestion['interests_nbr'] = 0
        if my_interests:
            interests = user_model.get_interests_by_user_id(suggestion['id'])
            if interests:
                my_tags = []
                for my_interest in my_interests:
                    my_tags.append(my_interest['title'])
                for interest in interests:
                    if interest['title'] in my_tags:
                        suggestion['interests_nbr'] += 1
        if correct:
            suggestions.append(suggestion)
        suggestions = sorted(suggestions, key=lambda k: k['distance'])
        suggestions = sorted(suggestions,
                             key=lambda k: k['interests_nbr'],
                             reverse=True)
        suggestions = sorted(suggestions,
                             key=lambda k: k['fame_rating'],
                             reverse=True)
    data = {
        'user':
        user,
        'suggestions':
        suggestions,
        'unread_messages_nbr':
        messages_model.get_unread_messages_nbr_by_user_id(session.get('id')),
        'incoming_requests_nbr':
        sympathys.get_incoming_requests_nbr(session.get('id')),
        'friends':
        sympathys.get_sympathys_list(session.get('id')),
        'online_users':
        get_online_users()
    }
    return render_template('suggestions.html', data=data)
Esempio n. 4
0
def edit_avatar():
    if 'id' in session:
        data = {
            'user':
            user_model.get_user_by_id(session.get('id'))[0],
            'unread_messages_nbr':
            messages_model.get_unread_messages_nbr_by_user_id(
                session.get('id')),
            'incoming_requests_nbr':
            sympathys.get_incoming_requests_nbr(session.get('id')),
            'friends':
            sympathys.get_sympathys_list(session.get('id'))
        }
        return render_template('edit-profile-avatar.html', data=data)
    else:
        return redirect('/')
Esempio n. 5
0
def profile(id_user=None):
    if not 'id' in session:
        return redirect('/')
    if 'id' in session:
        my_id = session.get('id')
        user = user_model.get_user_by_id(my_id)[0]
        friends = sympathys.get_sympathys_list(my_id)
        information = user_model.get_information(my_id)
        interests = user_model.get_interests_by_user_id(my_id)
        education = user_model.get_education_by_user_id(my_id)
        work = user_model.get_work_by_user_id(my_id)
        geolocation = geolocation_model.get_geolocation_by_user_id(my_id)

    if id_user:
        if not user_model.get_user_by_id(id_user):
            return render_template('404.html')
        user = user_model.get_user_by_id(id_user)[0]
        friends = sympathys.get_sympathys_list(id_user)
        information = user_model.get_information(id_user)
        interests = user_model.get_interests_by_user_id(id_user)
        education = user_model.get_education_by_user_id(id_user)
        work = user_model.get_work_by_user_id(id_user)
        geolocation = geolocation_model.get_geolocation_by_user_id(id_user)

        if id_user != session.get('id'):
            msg = str(session.get('firstname')) + ' ' + str(
                session.get('lastname')) + ' viewed your profile.'
            image = user_model.get_avatar(session.get('id'))
            notification_view.add_notification(session.get('id'), id_user, msg,
                                               'view', image)

    user['age'] = date.today().year - datetime.strptime(
        user['birth_date'], '%Y-%m-%d %H:%M:%S').year

    data = {
        'user':
        user,
        'friends':
        friends,
        'sympathys':
        sympathys,
        'information':
        information,
        'interests':
        interests,
        'education':
        education,
        'work':
        work,
        'geolocation':
        geolocation,
        'unread_messages_nbr':
        messages_model.get_unread_messages_nbr_by_user_id(session.get('id')),
        'incoming_requests_nbr':
        sympathys.get_incoming_requests_nbr(session.get('id')),
        'check_block':
        sympathys.check_block,
        'offline_users':
        get_offline_users(),
        'online_users':
        get_online_users()
    }
    return render_template('profile.html', data=data)