def new_post(): """ Write a new post with type publications : 1.public 2.subsets 3.uplines 4.directs 5.upline :return: Data from new post page. """ form = PostForm() if request.method == 'POST': subject = form.subject.data content = form.content.data type_publication = form.type_publication.data user_data = User.find_by_email(current_user.email) if type_publication == 'public': Post(user_data["email"], subject, content, type_publication=type_publication).insert( _type=type_publication) elif type_publication == 'uplines': uplines = current_user.find_uplines(current_user._id) if uplines: post = Post(user_data["email"], subject, content, type_publication=type_publication) post.insert(type_publication) for up in uplines: Post.connect(up.email, post._id, type_publication) else: flash("You have not any uplines.") return redirect(url_for('posts.new_post')) elif type_publication == 'subsets': subsets = User.find_sub(current_user._id) if subsets: post = Post(user_data["email"], subject, content, type_publication=type_publication) post.insert(type_publication) for sub in subsets: Post.connect(sub.email, post._id, type_publication) else: flash("You have not any subsets.") return redirect(url_for('posts.new_post')) elif type_publication == 'directs': directs = User.find_directs(current_user.email) if directs: post = Post(user_data["email"], subject, content, type_publication=type_publication) post.insert(type_publication) for direct in directs: Post.connect(direct.email, post._id, type_publication) else: flash("You have not any directs.") return redirect(url_for('posts.new_post')) elif type_publication == 'upline': upline = User.find_one(current_user.upline_phone_number) if upline: post = Post(user_data["email"], subject, content, type_publication=type_publication) post.insert(type_publication) Post.connect(upline["email"], post._id, type_publication) else: flash("You have not any upline.") return redirect(url_for('posts.new_post')) return redirect(url_for('posts.view_sent_posts')) return render_template("post/new_post.html", form=form)
def delete_message_outbox(post_id): user = User.find_by_email(current_user.email) if Post.delete_message_inbox(post_id, user): flash("Message deleted.") return redirect(url_for('messages.outbox'))
def inbox(): posts = Post.find_message(current_user.email) return render_template("message/inbox.html", posts=posts)
def admin_read_message(): posts = Post.admin_read_messages() return render_template("admin/read_message.html", posts=posts)
def admin_posts_delete(post_id): Post.admin_sent_posts_delete(post_id) flash("Post DELETED") return redirect(url_for('admins.admin_home'))
def admin_posts(): search = True msg = None if request.method == 'POST': if request.form["search"]: word = request.form["search"].strip() option = request.form["radio"] if option == 'author': user = User.find_by_email(word) if not user: msg = "There is no user by this email: {0}".format(word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) posts = Post.admin_find_posts_by_author(word) if posts: search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post by this author: {0}".format(word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) elif option == 'date': if '-' in word: date = word.split('-') if len(date) >= 2: posts = Post.admin_find_posts_by_date(*date) search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) elif word.isdigit(): date = [word] posts = Post.admin_find_posts_by_date(*date) search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post in this date: {0}\n Date format should be YEAR-MONTH-DAY-HOUR".format( word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) elif option == 'title': if ' ' in word: word = word.split(' ') posts = Post.admin_find_posts_by_title(*word) if posts: search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post by this title: {0}".format( word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) elif ' ' not in word: word = [word] posts = Post.admin_find_posts_by_title(*word) if posts: search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post by this title: {0}".format( word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) elif option == 'content': if ' ' in word: words = word.split(' ') posts = Post.admin_find_posts_by_content(*words) if posts: search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post by this content: {0}".format( word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) elif ' ' not in word: word = [word] posts = Post.admin_find_posts_by_content(*word) if posts: search = None return render_template("admin/posts.html", activate='active', search=search, msg=msg, posts=posts) else: msg = "There is no post by this content: {0}".format( word) return render_template("admin/posts.html", activate='active', search=search, msg=msg) else: msg = "Enter an email or title or date or a word of content." return render_template("admin/posts.html", activate='active', search=search, msg=msg)