Exemplo n.º 1
0
def ajax_delete_friend():
    user_id = request.args.get('user_id')
    if sympathys.check_sympathy(session.get('id'), user_id):
        if sympathys.check_request(session.get('id'), user_id) == 'sender':
            sympathys.remove_request(session.get('id'), user_id)
            status = 'sender'
        else:
            status = 'taker'
            sympathys.set_request_status_to_zero(session.get('id'), user_id)
        if not sympathys.unlike_user(session.get('id'), user_id):
            msg = str(session.get('firstname')) + ' ' + str(
                session.get('lastname')) + ' does not like you anymore.'
            image = user_model.get_avatar(session.get('id'))
            notification_view.add_notification(session.get('id'), user_id, msg,
                                               'unlike_user', image)
            rating = user_model.get_user_fame_rating(user_id) - 20
            user_model.update_user_rating(rating, user_id)
            return json.dumps({
                'ok': True,
                'error': "Unlike",
                'status': status
            })
        else:
            return json.dumps({'ok': False, 'error': "Something went wrong"})
    else:
        return json.dumps({'ok': False, 'error': "Something went wrong"})
Exemplo n.º 2
0
def ajax_add_comment():
    id_photo = request.form['id_photo']
    id_user = session.get('id')
    text = html.escape(request.form['text'])

    if not id_photo or not id_user or not text:
        return json.dumps({
            'ok': False,
            'error': "Something went wrong"
        })
    res = comments.add_comment(id_photo, id_user, text)
    to_whom_id = user_model.get_user_id_by_photo_id(id_photo)
    if to_whom_id != session.get('id'):
        msg = 'You have a new comment from ' + str(session.get('firstname')) + ' ' + str(session.get('lastname')) + '.'
        image = user_model.get_avatar(session.get('id'))
        notifications_view.add_notification(session.get('id'), to_whom_id, msg, 'comment', image)
    rating = user_model.get_user_fame_rating(to_whom_id) + 5
    user_model.update_user_rating(rating, to_whom_id)
    if not res:
        return json.dumps({
            'ok': False,
            'error': "The comment has not been added"
        })
    return json.dumps({
        'ok': True,
        'error': "Commented",
        'id_comment': res,
        'text': text
    })
Exemplo n.º 3
0
def ajax_like_back_user():
    user_id = request.args.get('user_id')
    if not sympathys.check_sympathy(session.get('id'), user_id):
        sympathys.like_back_user(session.get('id'), user_id)
        sympathys.add_users_to_sympathys(session.get('id'), user_id)

        msg = 'You like each other! Now you can chat with ' + str(
            session.get('firstname')) + ' ' + str(
                session.get('lastname')) + '.'
        image = user_model.get_avatar(session.get('id'))
        notification_view.add_notification(session.get('id'), user_id, msg,
                                           'like_back_user', image)
        rating = user_model.get_user_fame_rating(user_id) + 20
        user_model.update_user_rating(rating, user_id)
        return json.dumps({'ok': True, 'error': "Liked_back"})
Exemplo n.º 4
0
def ajax_like():
    id_photo = request.form['id_photo']
    id_user = request.form['id_user']
    if not id_photo or not id_user:
        return json.dumps({'ok': False, 'error': "Something went wrong"})
    res = likes.like(id_photo, id_user)
    if res:
        to_whom_id = user_model.get_user_id_by_photo_id(id_photo)
        if to_whom_id != session.get('id'):
            msg = str(session.get('firstname')) + ' ' + str(
                session.get('lastname')) + ' liked your photo.'
            image = user_model.get_avatar(session.get('id'))
            notification_view.add_notification(session.get('id'), to_whom_id,
                                               msg, 'like', image)
        rating = user_model.get_user_fame_rating(to_whom_id) + 5
        user_model.update_user_rating(rating, to_whom_id)
        if res == 'was':
            return json.dumps({'ok': True, 'error': "Was dislike"})
        return json.dumps({'ok': True, 'error': "Like"})
    else:
        return json.dumps({'ok': False, 'error': "Remove like"})
Exemplo n.º 5
0
def ajax_like_user():
    user_id = request.args.get('user_id')
    if photos_model.get_photos_nbr_by_id(session.get('id')) > 0:
        if photos_model.get_photos_nbr_by_id(user_id) < 1:
            return json.dumps({
                'ok':
                False,
                'error':
                "To like a user, he must have at least one photo uploaded"
            })
        check = sympathys.check_request(session.get('id'), user_id)
        if not check:
            res = sympathys.like_user(session.get('id'), user_id)
            if res:
                msg = str(session.get('firstname')) + ' ' + str(
                    session.get('lastname')) + ' likes you!'
                image = user_model.get_avatar(session.get('id'))
                notification_view.add_notification(session.get('id'), user_id,
                                                   msg, 'like_user', image)
                rating = user_model.get_user_fame_rating(user_id) + 20
                user_model.update_user_rating(rating, user_id)
                return json.dumps({'ok': True, 'error': "Liked"})
            else:
                return json.dumps({
                    'ok': False,
                    'error': "Something went wrong"
                })
        else:
            return json.dumps({'ok': False, 'error': "It's your friend"})
    else:
        return json.dumps({
            'ok':
            False,
            'error':
            "To like a user, you must have at least one photo uploaded"
        })
Exemplo n.º 6
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)