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 del_follow(search_user_id): login_user_manager = UserManager.load_models[session['username']] login_user_id = login_user_manager.object.id rel = UserRelationManager() # fol = rel.isFollower(login_user_id, search_user_id) rel.delete().And([('user1', '=', login_user_id), ('user2', '=', search_user_id)]).run() return redirect(request.referrer)
def block_friend(): if request.method == 'POST': user_nickname = session['username'] user = UserManager() if user.SelectUser(user_nickname): user_id = user.object.id friend_id = request.form['friend_id'] friend = UserRelationManager() if user_id and friend_id: friend.blockFriend(user_id , friend_id) return('ok') return('!ok') else: render_template('home.html')
def get_friends(self): relationManager = UserRelationManager() relationManager.getFriends(self.object.id) friend_list = [] for rel in relationManager.object: if rel.user1 == self.object.id: frend_id = rel.user2 else: frend_id = rel.user1 user = UserManager() user.get_user(frend_id) friend_list.append(user.object) return friend_list
def find_friend(): if request.method == 'GET': user_nickname = session['username'] user = UserManager() if user.SelectUser(user_nickname): user_id = user.object.id friend_nickname = request.args['friend_nickname'] friend = UserManager() if friend.SelectUser(friend_nickname): print('ok') friend_id = friend.object.id else: friend_id = 0 print('/ok') friend = UserRelationManager() if user_id and friend_id != 0: IsItYourFriend = friend.isFriend(user_id, friend_id) if IsItYourFriend == True: return redirect(url_for('nickname', nickname=friend_nickname)) elif friend_nickname == None: return redirect(url_for('home')) else: #context = {'Error': []} # context['Error:'].append("you don't have friend with that nickname") render_template('find_friend error.html') return ("you do not have friends with this nickname") else: return ("you do not have friends with this nickname")
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 user_page(nickname): context = {} login_user_manager = UserManager.load_models[session['username']] context['loginUser'] = login_user_manager login_user_id = login_user_manager.object.id search_user_manager = UserManager() search_user_manager.select().And([('nickname','=',nickname)]).run() search_user_id = search_user_manager.object.id context['user'] = search_user_manager relation = UserRelationManager() # fol = relation.isFollower(login_user_id,search_user_id) # context["fol"] = fol if relation.isFollower(login_user_id,search_user_id): context["friend_button_name"] = 'Cancel request' elif relation.isFollowed(login_user_id,search_user_id): context["friend_button_name"] = 'Accept request' elif relation.isFriend(login_user_id,search_user_id): context["friend_button_name"] = 'Is Friends' elif not relation.isFriend(login_user_id,search_user_id): context["friend_button_name"] = 'Isnt Friends' return render_template('home.html', context=context)
def get_friends(self): relationManager = UserRelationManager() return relationManager.getFriends(self.object.id)
def add_friend(self, id=None, nickname=None): if not (id or nickname): return relationManager = UserRelationManager() relationManager.addFriend(self.object.id, id)
def isfriend(self, user1, friend1): relationManager = UserRelationManager() relationManager.isFriend(user1, friend1)
def ifsender(self): relationManager = UserRelationManager() relationManager.IsSender(self.object.id)
def add_friend(): if request.method == 'POST': user = UserManager() user_nickname = session['username'] if user.SelectUser(user_nickname): user_id = user.object.id friend_id = request.form['friend_id'] func_type = request.form['func_type'] func_type = int(func_type) print(type(func_type)) print('kjgjgjgjf') friend = UserRelationManager() isfriend = friend.isFriend(user_id, friend_id) print(isfriend) print('Vasya privet') if isfriend == True: print('func_type') print(func_type) print("it's working") if func_type == 1: # Block print('You are blocking a friend.') if user_id and friend_id: friend.blockFriend(user_id, friend_id) return redirect(url_for('home')) elif func_type == 2: #Delete print('You are deliting a friend.') print('hallo mein freinde.') if user_id and friend_id: friend.delFriend(user_id, friend_id) return redirect(url_for('home')) elif func_type == 3: # AddFriend sender = user.ifsender() print('Hallo.') if sender == True: print('you are sender') return ("You are Sender You can't accept it.") else: if user_id and friend_id: print('You are adding a friend.') sender_id = user_id friend.addFriend(user_id, friend_id, sender_id) return redirect(url_for('home')) else: print('hey chuvak') if user_id and friend_id: sender = 0 print('hey good man') friend.addFriend(user_id, friend_id, sender) print(friend.addFriend(user_id, friend_id, sender)) return redirect(url_for('home')) else: return redirect(url_for('home'))