Beispiel #1
0
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)
Beispiel #2
0
def posts_create(theme_num):

    form = PostForm(request.form)

    if not form.validate():
        return render_template("posts/write.html",
                               form=form,
                               theme_id=theme_num)

    b = Topic(form.topic.data)
    old_topic = Topic.query.filter_by(name=form.topic.data).first()

    if not old_topic:
        b.theme_id = theme_num
        db.session().add(b)
        db.session().commit()
        Subject = Topic.query.filter_by(name=form.topic.data).first()

        a = Post(request.form.get("content"))
        a.topic = form.topic.data
        a.author = current_user.name
        a.account_id = current_user.id
        a.subject_id = Subject.id
        db.session().add(a)

        db.session().commit()

        return redirect(url_for("topic_id", theme_id=theme_num))

    else:
        flash("Topic already taken!")
        return render_template("posts/write.html",
                               form=form,
                               error="Topic already taken!",
                               theme_id=theme_num)
Beispiel #3
0
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))
Beispiel #4
0
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"))
Beispiel #5
0
def posts_reply(topic_id):
    form = ReplyForm(request.form)
    subject = Topic.query.filter_by(id=topic_id).first()

    a = Post(request.form.get("content"))
    a.topic = subject.name
    a.author = current_user.name
    a.account_id = current_user.id
    a.subject_id = subject.id
    db.session().add(a)

    db.session().commit()

    return redirect(url_for("post_id", topic_id=topic_id))
Beispiel #6
0
def posts_submit():
    form = PostForm(request.form)

    if not form.validate():
        return render_template('posts/submit.html', form=form)

    with session_scope() as session:
        post = Post(form.title.data, form.content.data)
        post.account_id = current_user.id

        session.add(post)
        session.commit()

    return redirect(url_for('posts_index'))
Beispiel #7
0
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))
Beispiel #8
0
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"))
Beispiel #9
0
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))
Beispiel #10
0
def posts_index():
    if request.method == "GET":
        return render_template("posts/list.html",
                               posts=Post.query.order_by(
                                   Post.date_created.desc()).all(),
                               form=PostForm())

    if not current_user.is_authenticated:
        return redirect("/auth/login")

    form = PostForm(request.form)
    if not form.validate():
        return render_template("posts/list.html",
                               form=form,
                               posts=Post.query.order_by(
                                   Post.date_created.desc()).all())

    p = Post(form.content.data)
    p.account_id = current_user.id

    db.session().add(p)
    db.session().commit()

    return redirect(url_for("posts_index"))