Example #1
0
def create_topic():
    form = TopicForm(request.form)

    form.tags.choices = [form.tags.data]

    if not form.validate():
        return render_template("topics/new.html", form=form)

    subject = form.subject.data
    body = form.body.data
    author_id = current_user.id

    initial_post = Post(body)
    initial_post.author_id = author_id
    topic = Topic(subject, author_id)
    topic.posts.append(initial_post)

    tag_names = form.tags.data[0].split(",")
    for tag_name in tag_names:
        tag = Tag.query.filter_by(name=tag_name).first()
        if not tag:
            tag = Tag(tag_name)
        topic.tags.append(tag)

    db.session().add(topic)
    db.session().commit()

    return redirect(url_for("topics_index"))
Example #2
0
def topics_create():
    form = TopicForm(request.form)
    if form.title.validate(form) and form.message.validate(form):
        place = db.session.query(Place).get(form.place.data)
        if form.place.data == 0:
            place_id = 0
        else:
            place_id = place.id
          
        topic = Topic(form.title.data, place_id)
        db.session().add(topic)
        db.session().commit()
        topic_timefix = Topic.query.get(topic.id)
        topic_timefix.date_created = datetime.now().replace(microsecond=0, second = 0)
        db.session().commit

        message = Message(form.message.data, topic.id, current_user.id)
        db.session().add(message)
        db.session().commit()
        message_timefix = Message.query.get(message.id)
        message_timefix.date_created = datetime.now().replace(microsecond=0, second = 0)
        db.session().commit()

        newTopicAccount = topicAccount.insert().values(topic_id=topic.id, account_id=current_user.id)
        db.session().execute(newTopicAccount)
        db.session.commit()

        return redirect(url_for("topics_index"))
    
    places = db.session.query(Place)
    form=TopicForm()
    form.place.choices = [("0", "---")] + [(i.id, i.name) for i in places]

    return render_template("topics/new.html", form = form, error="topic name must be between 1-100 characters and message between 1-1000 characters")
Example #3
0
def topics_create():
    form = TopicForm(request.form)

    if not form.validate():
        return render_template("topics/new.html", form=form)

    topic = Topic(form.name.data)

    db.session().add(topic)
    db.session().commit()

    return redirect(url_for("topics_index"))
Example #4
0
def topics_edit(topic_id):
    form = TopicForm(request.form)
    if not form.validate():
        return render_template("topics/edit.html", form=form,
                               topic=Topic.query.get(topic_id))

    t = Topic.query.get(topic_id)

    if current_user.admin:
        t.title = form.title.data
        db.session.commit()

    return redirect(url_for("topics_index"))
Example #5
0
def topics_create():
    form = TopicForm(request.form)

    if not form.validate():
        return render_template("topics/new_topic.html", form=form)

    t = Topic(form.title.data)
    t.creator = current_user.name

    if current_user.admin:
        db.session.add(t)
        db.session.commit()

    return redirect(url_for("topics_index"))
Example #6
0
def rename_topic(topic_id):
    form = TopicForm(request.form)

    topic = Topic.query.get(topic_id)
    topicname = Topic(form.name.data)

    if not form.validate():
        return render_template("topics/list.html",
                               topics=Topic.query.all(),
                               form=form)

    topic.name = topicname.name
    db.session().commit()

    return redirect(url_for("topics_index"))
Example #7
0
def topic_create():
    form = TopicForm(request.form)
    name = form.name.data

    # validoidaan syöte
    if not form.validate():
        return render_template("topic_creation_form.html", form=form)

    # tarkistetaan löytyykö aihe jo tietokannasta, estetään duplikaatti
    already_exists = Topic.topic_already_exists(name)
    if already_exists == True:
        return render_template("topic_list.html", topics=Topic.query.all())

    # lisätään tietokantaan
    new_topic = Topic(name=form.name.data)
    db.session.add(new_topic)
    db.session.commit()

    # paluu aihelistaan
    return render_template("topic_list.html", topics=Topic.query.all())
Example #8
0
def topics_form():
    check = db.session.query(Place).first()
    if check is None:
        firstplace = Place(name = "---", parent_id = None)
        db.session().add(firstplace)
        db.session.commit()

    places = db.session.query(Place)
    form=TopicForm()
    form.place.choices = [(i.id, i.name) for i in places]
       
    return render_template("topics/new.html", form = form)
Example #9
0
def topics_get_for_edit(topic_id):
    topic = Topic.query.get(topic_id)
    return render_template("topics/edit.html", form=TopicForm(title=topic.title),
                           topic=topic)
Example #10
0
def topics_form():
    return render_template("topics/new_topic.html", form=TopicForm())
Example #11
0
def topic_creation_form():
    return render_template("topic_creation_form.html", form=TopicForm())
Example #12
0
def rename_topic_index(topic_id):
    form = TopicForm(request.form)
    topic = Topic.query.get(topic_id)
    return render_template("topics/rename.html", form=form, topic=topic)
Example #13
0
def view_new_topic_form():
    tags = Tag.query.all()
    return render_template("topics/new.html", form=TopicForm(), tags=tags)