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() 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 add_friend(): if request.method == 'POST': user_nickname = session['username'] user = UserManager() if user.SelectUser(user_nickname): user_id = user.object.id friend_nickname = request.form['friend_nickname'] friend = UserManager() if friend.SelectUser(friend_nickname): friend_id = friend.object.id friend = UserRelationManager() if user_id and friend_id: friend.addFriend(user_id , friend_id) return('ok') return('!ok') else: render_template('home.html')
def edit(): nickname = session['username'] context = {} user = UserManager() if user.SelectUser(nickname): context['user'] = user if request.method == 'POST': user = user.getModelFromForm(request.form) if user.save(): context['user'] = user return redirect(url_for('home')) return render_template('edit.html', context=context)
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'))
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 registration(): print('hey man1') context = {'Error': []} if session.get('username') and request.method == 'GET': print('hey man2') nickname = session.get('username') user = UserManager() if user.SelectUser(nickname): print(user.object.id) print(user) context['user'] = user context['group'] = True if user.save(): return redirect(url_for('home')) else: return ('shit') else: context['group'] = False print(context['group']) elif request.method == 'POST': user = UserManager().getModelFromForm(request.form) if user.check_user(): context['Error'].append('wrong nickname or email') if not user.object.password: context['Error'].append('incorrect password') if context['Error']: return render_template('registration.html', context=context) if user.save(): UserManager.load_models[user.object.nickname] = user addToSession(user) return redirect(url_for('home')) context['Error'].append('incorrect data') return render_template('registr.html', context=context) else: context['group'] = False print('hey man 2.1') print(context['group']) return render_template('registr.html', context=context)