def friends_view(): context = {} if session.get('username', None): user = UserManager.load_models[session['username']] context['user'] = user context['loginUser'] = user friends_list = {} user_nickname = session['username'] user = UserManager() if user.SelectUser(user_nickname): user_id = user.object.id friend = UserRelationManager() friend.getFriends(user_id) friends = [] friends_request = [] friend_nickname = UserManager() for i in friend.object: friend_id = i.user2 friend_nickname.get_user(friend_id) if i.block == 2 or i.block == 1: friends_request.append(friend_nickname.object.nickname) else: friends.append(friend_nickname.object.nickname) context['friends_list'] = friends context['friends_request_list'] = friends_request return render_template('home.html', context = context)
def friends_view(): context = {} if session.get('username', None): user = UserManager.load_models[session['username']] context['user'] = user context['loginUser'] = user friends_list = {} user_nickname = session['username'] user = UserManager() if user.SelectUser(user_nickname): user_id = user.object.id friend = UserRelationManager() print('hey man') friend.getFriends(user_id) friends = [] friends_request = [] friend_nickname = UserManager() print(type(friend.object)) print(friend.object) if isinstance(friend.object, list): for i in friend.object: print('hey friend') print(i) friend_id = i.user2 friend_nickname.get_user(friend_id) if i.block == 2 or i.block == 1: friends_request.append(friend_nickname.object.nickname) else: friends.append(friend_nickname.object.nickname) elif friend.object == None: return ('YOU ARE ALONE.') else: print('friends') print(friend.object) if not friend.object.user2: return ('YOU ARE ALONE.') friend_id = friend.object.user2 print(type(friend_id)) print(friend_id) friend_nickname.get_user(friend_id) if friend.object.block == 2 or friend.object.block == 1: friends_request.append(friend_nickname.object.nickname) else: friends.append(friend_nickname.object.nickname) context['friends_list'] = friends context['friends_request_list'] = friends_request return render_template('home.html', context=context)
def get_user(self, _login, _password): """ Возвращает пользователя по имени и паролю или None в случае, если пользователь не найден Args: _login (String): логин пользователя _password (String): пароль пользователя Returns: User: найденный пользователь или None """ user_manager = UserManager() user = user_manager.get_user(_login, _password) return user