Esempio n. 1
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))
Esempio n. 2
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'))
Esempio n. 3
0
def edit_message(thread_id, message_id):
    message = Message.query.get(message_id)

    if message.account_id != current_user.id and current_user.role != "ADMIN":
        return login_manager.unauthorized()

    if request.method == "GET":
        form = MessageForm()
        form.content.data = message.content
        return render_template("messages/edit.html",
                               form=form,
                               thread_id=thread_id,
                               message_id=message_id)

    form = MessageForm(request.form)

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

    message.content = form.content.data
    db.session().commit()

    return redirect(url_for("get_messages_from_thread_id",
                            thread_id=thread_id))
Esempio n. 4
0
def thread_respond(thread_id):
    form = MessageForm(request.form)
    if not form.validate():
        return render_template("message_response_form.html", form = form)
    new_message = Message(title=form.title.data, content=form.content.data, time_of_sending=datetime.now(), author_id=current_user.id, thread_id=thread_id)
    db.session.add(new_message)
    db.session.commit()
    return render_template("thread_details.html", thread=Thread.query.get(thread_id))
Esempio n. 5
0
def messages_create(target):
    check_ban(target)
    form = MessageForm(request.form)
    if not form.validate():
        return redirect(url_for("discussion_home", target=target, page=1))
    m = Message(request.form.get("message"), target, current_user.get_id())
    db.session().add(m)
    db.session().commit()
    return redirect(url_for("discussion_home", target=target, page=1))
Esempio n. 6
0
def modify_message(message_id):
    form = MessageForm(request.form)

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

    m = Message.query.get(message_id)
    if m.account_id == current_user.id or current_user.get_role(
    ).role == "ADMIN":
        m.text = form.name.data
        db.session.commit()

    return redirect(url_for("group_messages", group_id=m.group_id))
Esempio n. 7
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))
Esempio n. 8
0
def messages_create():
    form = MessageForm(request.form)

    if not form.validate():
        return render_template("index.html",
                               messages=Message.query.all(),
                               form=form)

    m = Message(form.message.data)

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

    return redirect(url_for("index"))
Esempio n. 9
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"))
Esempio n. 10
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))
Esempio n. 11
0
def message_update(message_id):
    form = MessageForm(request.form)
    m = Message.query.get(message_id)
    u = current_user

    if m.user_id != u.id and not u.is_admin():
        return redirect(url_for("threads_view", thread_id=m.thread_id))

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

    m.message_text = form.message_text.data

    db.session.commit()

    return redirect(url_for("threads_view", thread_id=m.thread_id))
Esempio n. 12
0
def threads_reply(thread_id):
    form = MessageForm(request.form)

    if not form.validate():
        return threads_view(thread_id, form=form)

    thread = Thread.query.get(thread_id)

    if Category.query.get(thread.category_id) not in current_user.categories:
        return redirect(url_for("threads_index"))

    Thread.post_reply(thread_id=thread_id,
                      message_text=form.message_text.data,
                      user_id=current_user.id)

    return redirect(url_for("threads_view", thread_id=thread_id))
Esempio n. 13
0
def message_add(club_id):
    club = Club.query.get(club_id)
    if not club or current_user.id != club.leader_id:
        return redirect(url_for("clubs_index"))

    form = MessageForm(request.form)
    if not form.validate():
        return render_template("clubs/club.html", club=club)

    message = Message(form.message.data)
    message.club_id = club.id

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

    return redirect(url_for("club_page", club_id=club.id))
Esempio n. 14
0
def messages_edit(message_id):
    form = MessageForm(request.form)

    if not form.validate():
        return render_template("messages/edit.html",
                               form=form,
                               message=Message.query.get(message_id))

    m = Message.query.get(message_id)
    m.content = form.name.data

    if current_user.id == m.account_id:
        db.session.commit()

    return redirect(
        url_for("messages_read_one", topic_id=m.topic_id, message_id=m.id))
Esempio n. 15
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"))
Esempio n. 16
0
def message_new_comment(channel_id, message_id):

    messageform = MessageForm(request.form)

    if not messageform.validate() or messageform.body.data.isspace():
        return redirect(
            url_for("message_index",
                    channel_id=channel_id,
                    message_id=message_id))

    comment = Comment(messageform.body.data, current_user.username)
    comment.message_id = message_id
    comment.account_id = current_user.id

    db.session().add(comment)
    db.session().commit()

    return redirect(
        url_for("message_index", channel_id=channel_id, message_id=message_id))
Esempio n. 17
0
def thread_create():
    user_choices = request.form.getlist("choices")
    topics = []
    for user_choice in user_choices:
        topics.append(Topic.query.get(int(user_choice)))

    new_thread = Thread(title="väliaikainen otsikko", time_of_opening=datetime.now(), author_id=current_user.id, topics=topics)
    db.session.add(new_thread)
    db.session.commit()

    form = MessageForm(request.form)
    if not form.validate():
        return render_template("message_opening_form.html", form = form)
    new_message = Message(title=form.title.data, content=form.content.data, time_of_sending=datetime.now(), author_id=current_user.id, thread_id=new_thread.id)
    new_thread.title = new_message.title

    db.session.add(new_message)
    db.session.commit()
    return render_template("thread_details.html", thread = new_thread)
Esempio n. 18
0
def message_edit(param):
    toEdit = Message.query.filter_by(id=param).first()
    d = Discussion.query.filter_by(id=toEdit.discussion_id).first()
    check_ban(d.group_id)
    f = MessageForm()

    if toEdit.sender_id == current_user.get_id():
        if request.method == "GET":
            f.message.data = toEdit.get_message()
            return render_template("discussions/edit.html", form=f, id=param)
        form = MessageForm(request.form)
        if form.validate():
            Message.edit_message_with_id(param, request.form.get("message"))
            return redirect(
                url_for("discussion_home", target=toEdit.discussion_id,
                        page=1))

    return render_template("discussions/edit.html",
                           form=f,
                           id=param,
                           error="Message too short. Minimum 2 characters")
Esempio n. 19
0
def message_edit(message_id):
    f = MessageForm()

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

    m = Message.query.get(message_id)
    m.body = f.body.data
    m.subject = f.subject.data
    m.read = False

    for c in m.categories:
        m.categories.remove(c)

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

    db.session.commit()

    return redirect(url_for("messages_index"))
Esempio n. 20
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 + "/")
Esempio n. 21
0
def messages_edit(message_id):
  m = Message.query.get(message_id)
  topic_id = m.topic_id

  if str(m.account_id) != str(current_user.id):
    return redirect(url_for('messages_index', topic_id = topic_id))
  
  if request.method == "GET":
    form = MessageForm()
    form.message.data = m.message
    return render_template("messages/edit.html", form = form, message = m)
  
  # If POST
  form = MessageForm(request.form)

  if not form.validate():
    return render_template("messages/edit.html", form = form, message = m)
    
  m.message = form.message.data

  db.session().commit()

  return redirect(url_for("messages_index", topic_id=topic_id))
Esempio n. 22
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 + "/")
Esempio n. 23
0
def messages_edit(message_id):
    message = Message.query.get(message_id)
    
    # tarkistetaan onko kirjautunut käyttäjä viestin omistaja tai admin
    if (message.author_id != current_user.id and current_user.is_admin == False):
        return login_manager.unauthorized()
    
    # haetaan lomakedata
    form = MessageForm(request.form)
    
    # tallennetaan viestin thread_id palautus-urlia varten
    thread_id = message.thread_id

    # validoidaan
    if not form.validate():
        return render_template("message_editing_form.html", form=MessageForm(), message_id=message_id)
    
    # päivitetään viesti
    message.title = form.title.data
    message.content = form.content.data
    db.session.commit()

    # palataan keskusteluketjun näkymään
    return redirect(url_for("thread_details", thread_id = thread_id))