def send_message(): is_valid = Message.validate_form(request.form) if not is_valid: return redirect('/login') print(request.form["which_form"]) data = { "content": request.form["content"], "recipient_id": request.form["which_form"], "account_id": session["user_id"] } print(data) new_message_id = Message.insert_one(data) return redirect('/login')
def validate_message(sent_to_id): data = { "sent_to": request.form["sent_to"], "content": request.form["content"], "title": request.form["title"], "account_id": session["user_id"] } data1 = {"username": request.form["sent_to"]} if not Message.validate_message(data): return redirect(f"/send_message/{sent_to_id}") elif len(Account.get_account_by_username(data1)) != 1: flash("username is invalid or doesn't exist.") return redirect(f"/send_message/{sent_to_id}") else: Message.send_message(data) return redirect("/dashboard")
def login_successs(): if "user_id" not in session: return redirect("/") else: data = {"id": session["user_id"]} messages = Message.get_message_to_account(data) print(messages) account_list = Account.get_account_exclude_id(data) print(account_list) total_sent = Message.total_message_sent(data) print(total_sent) total_received = Message.total_message_received(data) print(total_received) return render_template("private_wall.html", messages=messages, account_list=account_list, first_name=session["first_name"], total_sent=total_sent, total_received=total_received)
def login_successs(): if "user_id" not in session: return redirect("/") else: data = { "account_id": session["user_id"], "sent_to": session["username"] } my_posts = Post.get_posts_own(data) total_posts = Post.get_total_posts_own(data) my_follows = Post_Follow.posts_followed_by_user(data) messages = Message.get_message_received(data) total_message = Message.get_total_message_received(data) recent_posts = Post.most_recent_posts() return render_template("user_home.html", username=session["username"], my_posts=my_posts, total_posts=total_posts, my_follows=my_follows, messages=messages, total_message=total_message, recent_posts=recent_posts)
def show_message(message_id): data = {"id": message_id} message = Message.display_message(data) return render_template("display_message.html", message=message)
def delete_message(message_id): data = {"id": message_id} Message.delete_message(data) return redirect("/dashboard")
def delete_message(message_id): data = {"message_id": message_id} Message.delete_one(data) return redirect('/login')