def posts_create(thread_id): thread = Thread.query.get_or_404(thread_id) form = PostForm(request.form) if not form.validate(): return render_template("posts/new.html", form = form, thread_id = thread_id, title = thread.title ) try: thread.modification_time = db.func.current_timestamp() posted = Post(form.content.data) posted.account_id = current_user.id posted.thread_id = thread_id db.session().add(posted) db.session().commit() flash("Your comment was posted", "alert alert-info") except: db.session.rollback() flash("Error occurred, comment was not posted", "alert alert-danger") return redirect(url_for("posts_thread", thread_id=thread_id))
def threads_create(): form = ThreadForm(request.form) if not form.validate(): return render_template("threads/new_thread.html", form=form) try: # luodaan uusi lanka ja sille ID thread = Thread(form.title.data) thread.owner_id = current_user.id db.session.add(thread) db.session.flush() db.session.refresh(thread) # luodaan uusi postaus posted = Post(form.content.data) posted.account_id = current_user.id posted.thread_id = thread.id db.session().add(posted) db.session().commit() flash("Your new post was saved", "alert alert-info") return redirect(url_for("posts_index")) except: db.session.rollback() flash("Error occurred, could not save post", "alert alert-danger") return render_template("threads/new_thread.html", form=form)
def threads_create(): if request.method == "GET": return render_template("threads/new.html", form=ThreadForm()) form = ThreadForm(request.form) if not form.validate(): return render_template("threads/new.html", form=form) # Create Thread dbThread = Thread(form.topic.data) db.session().add(dbThread) db.session().flush() # Add Thread category dependicies if (form.yleinen.data == True): dbCategory = Category.query.filter_by(name="Yleinen").first() dbThread.categories.append(dbCategory) if (form.retro.data == True): dbCategory = Category.query.filter_by(name="Retro").first() dbThread.categories.append(dbCategory) if (form.wii.data == True): dbCategory = Category.query.filter_by(name="Wii").first() dbThread.categories.append(dbCategory) if (form.wiiu.data == True): dbCategory = Category.query.filter_by(name="WiiU").first() dbThread.categories.append(dbCategory) if (form.switch.data == True): dbCategory = Category.query.filter_by(name="Switch").first() dbThread.categories.append(dbCategory) if (form.ds.data == True): dbCategory = Category.query.filter_by(name="DS").first() dbThread.categories.append(dbCategory) if (form.threeDs.data == True): dbCategory = Category.query.filter_by(name="3DS").first() dbThread.categories.append(dbCategory) # Create Post dbPost = Post(form.message.data, 1) dbPost.account_id = current_user.id dbPost.thread_id = dbThread.id db.session().add(dbPost) db.session().commit() return redirect(url_for("threads_index"))
def post_create(thread_id): form = PostForm(request.form) form.content.data = escape(form.content.data) if not form.validate(): return render_template("post/new.html", form=form, thread_id=thread_id) if not current_user.is_authenticated: flash("Authentication error") return redirect(url_for("category_index")) p = Post(form.content.data) p.account_id = current_user.id p.thread_id = thread_id db.session().add(p) db.session().commit() return redirect(url_for("thread_view", thread_id=thread_id))
def threads_create(): form = ThreadForm(request.form) if not form.validate(): return render_template("threads/newthread.html", form=ThreadForm()) t = Thread(form.header.data) db.session().add(t) db.session().commit() p = Post(form.content.data) p.account_id = current_user.id p.thread_id = Thread.find_by_name(t.header) db.session().add(p) db.session().commit() return redirect(url_for("threads_index"))
def thread_reply(thread_id): thread = Thread.query.get(thread_id) form = PostForm(request.form) if not form.validate(): return redirect(url_for("view_thread", thread_id=thread_id, form=form)) post = Post(form.message.data) post.user_id = current_user.id post.thread_id = thread.id db.session().add(post) db.session().commit() return redirect( url_for("view_thread", thread_id=thread_id, form=ThreadForm()))
def posts_new(threadId): if request.method == "GET": return render_template("posts/new.html", form=PostForm(), threadId=threadId) form = PostForm(request.form) if not form.validate(): return render_template("posts/new.html", form=form, threadId=threadId) dbPost = Post(form.message.data, 0) dbPost.account_id = current_user.id dbPost.thread_id = threadId db.session().add(dbPost) db.session().commit() return redirect(url_for("threads_open", threadId=threadId))