def search_page(user_id, query): user = UserDatabaseOPS.select_user_with_id(user_id) if current_user != user: abort(403) if request.method == 'GET': query_in_users = UserDatabaseOPS.select_users_for_search( query, user_id) query_in_knots = KnotDatabaseOPS.select_knots_for_search(query) return render_template('search_page.html', signed_in=True, user=user, users=query_in_users, knots=query_in_knots, query=query) else: if 'delete_knot' in request.form: knot_id = request.form['delete_knot'] print("Update Knot function is not working on the Search Page :(") elif 'update' in request.form: knot_id = request.form['update'] print("Update Knot function is not working on the Search Page :(") elif 'like' in request.form: knot_id = request.form['like'] is_like = NotificationDatabaseOPS.check_like( knot_id, user.id, True) if is_like: NotificationDatabaseOPS.delete_relation(knot_id, user.id, True) NotificationDatabaseOPS.decrease_knot_like(knot_id) else: NotificationDatabaseOPS.insert_relation(knot_id, user.id, True) NotificationDatabaseOPS.increase_knot_like(knot_id) elif 'reknot' in request.form: knot_id = request.form['reknot'] is_reknot = NotificationDatabaseOPS.check_reknot( knot_id, user.id, False) if is_reknot: NotificationDatabaseOPS.delete_relation( knot_id, user.id, False) NotificationDatabaseOPS.decrease_knot_reknot(knot_id) else: NotificationDatabaseOPS.insert_relation( knot_id, user.id, False) NotificationDatabaseOPS.increase_knot_reknot(knot_id) elif 'follow' in request.form: target_user = request.form['target_user'] UserDatabaseOPS.follow(user_id, target_user) elif 'unfollow' in request.form: target_user = request.form['target_user'] UserDatabaseOPS.unfollow(user_id, target_user) else: print(request.form) query_in_users = UserDatabaseOPS.select_users_for_search( query, user_id) query_in_knots = KnotDatabaseOPS.select_knots_for_search(query) return render_template('search_page.html', signed_in=True, user=user, users=query_in_users, knots=query_in_knots, query=query)
def user_profile_page(user_id): user = UserDatabaseOPS.select_user_with_id(user_id) if user is -1: abort(404) user_check = True if current_user != user: user_check = False if request.method == 'GET': real_name = UserDatabaseOPS.select_user_detail(user.username) my_city = CityDatabaseOPS.select_city(real_name.city, real_name.country) cities = CityDatabaseOPS.select_all_cities() knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id) like_list = KnotDatabaseOPS.get_likes(user.id) followers = UserDatabaseOPS.get_followers(user.id) followings = UserDatabaseOPS.get_following(user.id) lengths = { 'knot_len': len(knot_list), 'like_len': len(like_list), 'followers_len': len(followers), 'followings_len': len(followings) } random_users = UserDatabaseOPS.get_random_users(current_user.id) return render_template('user_profile.html', signedin=True, user=user, real_name=real_name, my_city=my_city, cities=cities, knot_list=knot_list, user_check=user_check, likes=like_list, followers=followers, followings=followings, lengths=lengths, random=random_users) else: if 'changeImage' in request.form: user.profile_pic = request.form['imageURL'] my_name = request.form['my_name'] my_surname = request.form['my_surname'] user.cover_pic = request.form['coverURL'] city_id = request.form['city_id'] cities = CityDatabaseOPS.select_all_cities() real_name = UserDatabaseOPS.select_user_detail(user.username) if real_name == -1: UserDatabaseOPS.add_user_detail(user.username, my_name, my_surname, city_id) else: UserDatabaseOPS.update_user_detail(user.username, my_name, my_surname, city_id) UserDatabaseOPS.update_user(user.username, user.password, user.profile_pic, user.cover_pic, user.mail_address) real_name = UserDatabaseOPS.select_user_detail(user.username) my_city = CityDatabaseOPS.select_city(real_name.city, real_name.country) knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id) like_list = KnotDatabaseOPS.get_likes(user_id) followers = UserDatabaseOPS.get_followers(user_id) followings = UserDatabaseOPS.get_following(user_id) lengths = { 'knot_len': len(knot_list), 'like_len': len(like_list), 'followers_len': len(followers), 'followings_len': len(followings) } random_users = UserDatabaseOPS.get_random_users(current_user.id) if 'deleteReal' in request.form: user = UserDatabaseOPS.select_user_with_id(user_id) cities = CityDatabaseOPS.select_all_cities() UserDatabaseOPS.delete_user_detail(user.username) real_name = UserDatabaseOPS.select_user_detail(user.username) my_city = CityDatabaseOPS.select_city(real_name.city, real_name.country) knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id) like_list = KnotDatabaseOPS.get_likes(user.id) followers = UserDatabaseOPS.get_followers(user.id) followings = UserDatabaseOPS.get_following(user.id) lengths = { 'knot_len': len(knot_list), 'like_len': len(like_list), 'followers_len': len(followers), 'followings_len': len(followings) } random_users = UserDatabaseOPS.get_random_users(current_user.id) if 'follow' in request.form: user = UserDatabaseOPS.select_user_with_id(user_id) target_user = request.form['target_user'] cities = CityDatabaseOPS.select_all_cities() UserDatabaseOPS.follow(user_id, target_user) real_name = UserDatabaseOPS.select_user_detail(user.username) my_city = CityDatabaseOPS.select_city(real_name.city, real_name.country) knot_list = KnotDatabaseOPS.select_knots_for_owner(user.id) like_list = KnotDatabaseOPS.get_likes(user.id) followers = UserDatabaseOPS.get_followers(user.id) followings = UserDatabaseOPS.get_following(user.id) lengths = { 'knot_len': len(knot_list), 'like_len': len(like_list), 'followers_len': len(followers), 'followings_len': len(followings) } random_users = UserDatabaseOPS.get_random_users(current_user.id) return render_template('user_profile.html', signedin=True, user=user, real_name=real_name, my_city=my_city, cities=cities, knot_list=knot_list, user_check=user_check, likes=like_list, followers=followers, followings=followings, lengths=lengths, random=random_users)