def index():
    if session.get('token'):

        r = requests.get(
            settings['GATEWAY_URL'] + 'api/v1/images/',
            headers={'Authorization': f'JWT {session.get("token")}'})
        if r.status_code == 200:
            images = r.json()
        else:
            images = []

        data = {
            'all_posts': 'all_user_post',
            'all_friends': all_friends(session.get('id_user_logged')),
            "get_user_by_id": get_user_by_id,
            "images": images,
            "liked": 'liked',
            "disliked": 'disliked',
            "len_post_likes": 'len_post_likes',
            "len_post_dislikes": 'len_post_dislikes',
            'users_online': 'get_users_online_list()'
        }
        return render_template('newsfeed.html', data=data)

    return render_template('index-register.html')
Beispiel #2
0
def get_not_friends(id_user):
    not_friends = []
    if not session.get('location'):
        return not_friends
    lon1 = session.get('location')[0].get('longitude')
    lat1 = session.get('location')[0].get('latitude')

    users_list = get_users_and_locations(id_user)
    friends_list = all_friends(id_user)

    friends_id = []
    for i in friends_list:
        if i['id_requester'] != id_user:
            friends_id.append(i['id_requester'])
        if i['id_user_requested'] != id_user:
            friends_id.append(i['id_user_requested'])

    for user in users_list:
        if user['id_user'] not in friends_id and not if_user_blocked(
                id_user, user['id_user']):
            lon2 = user.get('longitude')
            lat2 = user.get('latitude')
            user['distance'] = round(
                calculate_distanse(lat1, lon1, lat2, lon2), 2)
            if user['distance'] < 100:
                not_friends.append(user)
    return not_friends
Beispiel #3
0
def chat():
	if not session.get('id_user_logged'):
		return redirect(url_for('index'))
	context = {'chat_room': 'room_for_all'}
	data = {
		'friends': all_friends_request(session.get('id_user_logged')),
		"all_friends": all_friends(session.get("id_user_logged")),
		'users_online': get_users_online_list()
	}

	try:
		room_data = get_chat_room_by_name(request.form['room_name'])
		messages = get_messages_by_room_id(room_data[0]['id_chat_room'])
		if messages:
			context['messages'] = messages
		else:
			context['messages'] = None
	except:
		return redirect(url_for('index'))

	try:
		context['chat_room'] = request.form['room_name']
		context['chat_to'] = check_user(request.form['chat_to'], request.form['chat_to'])
		print("-----")
		print(context['chat_to'])
		print(check_user(request.form['chat_to'], request.form['chat_to']))
		print(request.form['chat_to'])
		print("-----")
		context['chat_from'] = check_user(request.form['chat_from'], request.form['chat_from'])
	except:
		return redirect(url_for('index'))

	return render_template('newsfeed-messages.html', context=context, data=data)
Beispiel #4
0
def search():
	id_user = session.get('id_user_logged')
	if id_user:
		users_query = get_search_users(id_user)
		data = {
			'users_query': users_query,
			'all_friends': all_friends(session.get('id_user_logged'))
		}
		return render_template('people-search.html', data=data)
	return redirect("/")
Beispiel #5
0
def friends():
    if session.get('id_user_logged'):
        data = {
            'user': get_user_by_id(session.get('id_user_logged')),
            'get_by_id': get_user_by_id,
            'friends': all_friends_request(session.get('id_user_logged')),
            "all_friends": all_friends(session.get("id_user_logged")),
            'users_online': get_users_online_list()
        }
        return render_template("newsfeed-friends.html", data=data)
    return redirect("/")
def get_friendlist(id_user):
    req = all_friends(id_user)
    if not req:
        return None
    friends_ids = []
    for i in req:
        if i['id_requester'] == id_user:
            friends_ids.append(i['id_user_requested'])
        if i['id_user_requested'] == id_user:
            friends_ids.append(i['id_requester'])
    frends_data = []
    for i in friends_ids:
        frends_data.append(get_user_by_id(i))
    return frends_data
Beispiel #7
0
def user_friends(id_user=None):
	if not session.get('user_data') and not id_user:
		return redirect('/')
	if id_user:
		user = get_user_by_id(id_user)
	else:
		user = session.get('user_data')
	friends = all_friends(user['id_user'])
	data = {
		'user': user,
		'get_by_id': get_user_by_id,
		'friends': friends,
		'all_friends': friends
	}
	return render_template("timeline-friends.html", data=data)
Beispiel #8
0
def index():
    if session.get('id_user_logged'):
        data = {
            'all_posts': all_user_post,
            'all_friends': all_friends(session.get('id_user_logged')),
            "get_user_by_id": get_user_by_id,
            "all_post_comments": all_post_comments,
            "liked": liked,
            "disliked": disliked,
            "len_post_likes": len_post_likes,
            "len_post_dislikes": len_post_dislikes,
            'users_online': get_users_online_list()
        }
        return render_template('newsfeed.html', data=data)
    return render_template('index-register.html')
Beispiel #9
0
def people_nearby():
    if not session.get('id_user_logged'):
        return redirect('/')
    id_user = session.get('id_user_logged')
    user = get_user_by_id(id_user)

    not_friends = get_not_friends(id_user)
    session['not_friends'] = not_friends

    data = {
        'user': user,
        'all_friends': all_friends(user['id_user']),
        'not_friends': not_friends,
        'users_online': get_users_online_list()
    }
    return render_template("newsfeed-people-nearby.html", data=data)