def notifications(): if not 'id' in session: return redirect('/') user = user_model.get_user_by_id(session.get('id'))[0] notifications = notification_model.get_notification_by_user_id( session.get('id')) if notifications: notifications = sorted(notifications, key=lambda k: k['date_of_creation'], reverse=True) data = { 'user': user, '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')), 'notifications': notifications, 'online_users': get_online_users(), 'get_user_by_id': user_model.get_user_by_id, } return render_template('notifications.html', data=data)
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)
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)
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('/')
def search(): if not 'id' in session: return redirect('/') 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')), 'get_user_by_id': user_model.get_user_by_id, 'online_users': get_online_users() } return render_template('search.html', data=data)
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('/')
def photos(id_user=None): if not 'id' in session and not id_user: return redirect('/') if 'id' in session: id = session.get('id') user = user_model.get_user_by_id(id)[0] photos = photos_model.get_photos_by_id(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] photos = photos_model.get_photos_by_id(id_user) data = { 'user': user, 'photos': photos, 'get_user_by_id': user_model.get_user_by_id, 'get_avatar': user_model.get_avatar, 'likes': likes.photo_likes, 'dislikes': likes.photo_dislikes, 'check_like': likes.check_like, 'check_dislike': likes.check_dislike, 'get_comments_by_photo_id': comments.get_comments_by_photo_id, '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')), 'online_users': get_online_users() } return render_template('photos.html', data=data)
def messages(with_id=None): if 'id' in session: dialogue_id = None if with_id: if not user_model.get_user_by_id(with_id): return render_template('404.html') my_id = session.get('id') if sympathys_model.check_sympathy(my_id, with_id): if not messages_model.check_dialogue(my_id, with_id): dialogue_name = my_id + with_id if messages_model.create_dialogue(dialogue_name, my_id, with_id): dialogue_id = messages_model.get_dialogue_id( my_id, with_id) else: dialogue_id = messages_model.get_dialogue_id( my_id, with_id) else: return redirect('/profile/id' + str(with_id)) data = { 'user': user_model.get_user_by_id(session.get('id'))[0], 'get_user_by_id': user_model.get_user_by_id, 'dialogues': messages_model.get_dialogues_by_user_id(session.get('id')), 'messages': messages_model.get_messages_by_dialogue_id, 'get_last_message_by_dialogue_id': messages_model.get_last_message_by_dialogue_id, 'get_unread_messages_nbr': messages_model.get_unread_messages_nbr, 'unread_messages_nbr': messages_model.get_unread_messages_nbr_by_user_id( session.get('id')), 'dialogue_id': dialogue_id, 'incoming_requests_nbr': sympathys_model.get_incoming_requests_nbr(session.get('id')), 'online_users': get_online_users() } return render_template('messages.html', data=data) return redirect('/')
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)