示例#1
0
def threads_create():

    categories = [(c.id, c.name) for c in Category.query.all()]

    if request.method == "GET":
        form = ThreadForm()
        form.categories.choices = categories
        return render_template("threads/new.html", form=form)

    form = ThreadForm(request.form)
    form.categories.choices = categories

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

    t = Thread(form.title.data)
    t.account_id = current_user.id

    categories = form.categories.data
    for c_id in categories:
        c = Category.query.get(c_id)
        t.categories.append(c)

    db.session().add(t)
    db.session().flush()

    m = Message(form.content.data)
    m.thread_id = t.id
    m.account_id = current_user.id

    db.session().add(m)
    db.session().commit()

    return redirect(url_for("threads_index"))
示例#2
0
def messages_create(thread_id):
    form = MessageForm(request.form)

    if not form.validate():
        thread = Thread.query.filter_by(id=thread_id).first()
        title = thread.title

        return render_template(
            "messages/list.html",
            messages=Message.query.filter_by(thread_id=thread_id).order_by(
                Message.date_created),
            thread_id=thread_id,
            title=title,
            form=form)

    m = Message(form.content.data)
    m.thread_id = thread_id
    m.account_id = current_user.id

    db.session().add(m)
    db.session().commit()

    t = Thread.query.filter_by(id=thread_id).first()
    t.date_modified = datetime.utcnow()
    db.session().commit()

    return redirect(url_for("get_messages_from_thread_id",
                            thread_id=thread_id))
示例#3
0
def messages_create(channel_id):

    messageform = MessageForm(request.form)
    channel = Channel.query.get(channel_id)

    if not messageform.validate() or messageform.body.data.isspace():
        return render_template(
            "channels/channel.html",
            messageform=MessageForm(),
            channel=channel,
            que=Message.count_how_many_comments_get_first(channel_id),
            my_channels=Channel.get_my_channels(current_user.id),
            all_channels=Channel.get_channels_where_not_in(current_user.id),
            allready_join=Channel.is_joined(channel_id, current_user.id),
            error="message must be 2 character length",
            public_channels=Channel.get_all_publics())

    message = Message(messageform.body.data, current_user.username)
    message.account_id = current_user.id
    message.channel_id = channel_id

    db.session().add(message)
    db.session().commit()

    return redirect(
        url_for("one_channel_index", channel_id=channel_id, sort='first'))
示例#4
0
def messages_create():
    form = MessageForm(request.form)

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

    t = Message(form.name.data, form.messagetext.data)
    t.account_id = current_user.id
    t.category_id = request.form['category_id']

    db.session().add(t)
    db.session().commit()
  
    return redirect(url_for("messages_index"))
示例#5
0
def message_new(group_id):
    form = MessageForm(request.form)
    if not form.validate():
        return render_template("messages/newMessage.html", form=form)

    m = Message(form.name.data)
    m.text = m.text
    m.account_id = current_user.id
    m.group_id = group_id

    db.session().add(m)
    db.session().commit()

    return redirect(url_for("group_messages", group_id=group_id))
示例#6
0
def messages_create(topic_id):
    form = MessageForm(request.form)

    if not form.validate():
      return render_template("messages/new.html", form = form, topic_id=topic_id)
    
    m = Message(form.message.data)
    m.account_id = current_user.id
    m.topic_id = topic_id

    db.session().add(m)
    db.session().commit()

    return redirect(url_for("messages_index", topic_id=topic_id))
示例#7
0
def messages_create():
    f = MessageForm()

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

    m = Message(f.subject.data, f.body.data)
    m.account_id = current_user.id

    for c in f.categories.data:
        cat = Category.query.get(c)
        m.categories.append(cat)

    db.session.add(m)
    db.session.commit()

    return redirect(url_for("messages_index"))
示例#8
0
def messages_create(topic_id):
    form = MessageForm(request.form)

    if not form.validate():
        return render_template("topics/one_topic.html",
                               form=form,
                               topic=Topic.query.get(topic_id),
                               messages=Message.query.filter_by(
                                   topic_id=topic_id,
                                   reply_id=None).paginate(page=1,
                                                           per_page=5,
                                                           error_out=False))

    m = Message(form.name.data)
    m.author = current_user.name
    m.account_id = current_user.id
    m.topic_id = topic_id

    db.session.add(m)
    db.session.commit()

    return redirect("/topics/" + topic_id + "/")
示例#9
0
def messages_reply(topic_id, message_id):
    form = MessageForm(request.form)

    if not form.validate():
        return render_template(
            "messages/one.html",
            topic=Topic.query.get(topic_id),
            form=form,
            message=Message.query.get(message_id),
            replies=Message.query.filter_by(reply_id=message_id).all(),
            further_replies=Message.query.filter_by(topic_id=topic_id))

    reply = Message(form.name.data)
    reply.author = current_user.name
    reply.account_id = current_user.id
    reply.topic_id = topic_id
    reply.reply_id = message_id

    db.session.add(reply)
    db.session.commit()

    return redirect("/topics/" + topic_id + "/" + "messages" + "/" +
                    message_id + "/")