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))
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)
def chats_view(chat_id): if not _member_of(current_user.id, chat_id): abort(403) chat = Chat.get(chat_id) if not chat: return redirect(url_for('chats_all')) return render_template("chats/view.html", chat=chat, messages=Message.find_all_in_chat(chat_id), form=MessageForm())
def message_view(message_id): 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)) f = MessageForm() f.message_text.data = m.message_text return render_template("threads/edit.html", message=m, form=f)
def topics_get_one_paginated(topic_id, page=1): per_page = 5 messages = Message.query.filter_by(topic_id=topic_id, reply_id=None) replies = Message.query.filter_by(topic_id=topic_id) mark_messages_read(messages) return render_template("topics/one_topic.html", form=MessageForm(), topic=Topic.query.get(topic_id), replies=replies, messages=messages .paginate(page, per_page, False))
def get_messages_from_thread_id(thread_id): 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=MessageForm())
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"))
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")
def group_messages(group_id): categories = Groups.categories(group_id) messages = Groups.findMessagesByGroup(group_id) ug = user_getter() g = Groups.query.get(group_id) return render_template("messages/messages.html", messages=messages, group_id=group_id, g=g, ug=ug, categories=categories, form=MessageForm())
def messages_read_one(topic_id, message_id): replies = Message.query.filter_by(reply_id=message_id).all() further_replies = Message.query.filter_by(topic_id=topic_id) mark_messages_read(replies) return render_template("messages/one.html", topic=Topic.query.get(topic_id), form=MessageForm(), message=Message.query.get(message_id), replies=replies, further_replies=further_replies)
def club_kick(club_id, user_id): club = Club.query.get(club_id) user = User.query.get(user_id) if user not in club.members: return render_template("clubs/club.html", club=club, messageForm=MessageForm(), clubNameForm=ChangeClubNameForm(), clubHobbyForm=ChangeClubHobbyForm()) club.members.remove(user) db.session().commit() return redirect(url_for("club_page", club_id=club.id))
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 + "/")
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))
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 + "/")
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))
def discussion_home(target, page=1): if page < 1: return redirect(url_for("discussion_home", target=target, page=1)) d = Discussion.query.filter_by(id=target).first() check_ban(d.group_id) disc = Message.find_messages_with_usernames(target, page) if not disc and page != 1: return redirect( url_for("discussion_home", target=target, page=page - 1)) group = Groups.query.filter_by(id=d.group_id).first() return render_template("discussions/index.html", messages=disc, form=MessageForm(), target=target, ownerID=group.owner_id, current=page)
def message_index(channel_id, message_id): c = Channel.query.get(channel_id) m = Message.query.get(message_id) comments = [] if m is not None: comments = m.comments return render_template( "messages/message.html", channel=c, message=m, comments=comments, messageform=MessageForm(), all_channels=Channel.get_channels_where_not_in(current_user.id), my_channels=Channel.get_my_channels(current_user.id), public_channels=Channel.get_all_publics())
def one_channel_index(channel_id, sort): query = [] account_count = Channel.count_accounts(channel_id) if sort == 'first': query = Message.count_how_many_comments_get_first(channel_id) elif sort == 'last': query = Message.count_how_many_comments_get_last(channel_id) return render_template( "channels/channel.html", messageform=MessageForm(), channel=Channel.query.get(channel_id), que=query, 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), public_channels=Channel.get_all_publics(), account_count=account_count)
def messages_edit_form(message_id): message_to_be_edited = Message.query.get(message_id) form = MessageForm() form.title.data = message_to_be_edited.title form.content.data = message_to_be_edited.content return render_template("message_editing_form.html", form=form, message_id=message_id)
def thread_response_form(thread_id): return render_template("message_response_form.html", form=MessageForm(), thread_id=thread_id)
def index(): return render_template("index.html", messages=Message.query.all(), form=MessageForm())
def messages_form(topic_id): return render_template("messages/new.html", form = MessageForm(), topic_id=topic_id)
def messages_form(): return render_template("messages/new.html", form = MessageForm())
def message_form(group_id): return render_template("messages/newMessage.html", form=MessageForm(), group_id=group_id)
def chats_post(chat_id): if not _member_of(current_user.id, chat_id): abort(403) form = MessageForm(request.form) Message.create(ChatUser.find(current_user.id, chat_id).id, form.text.data) return redirect("/chats/" + chat_id)
def messages_get_for_edit(message_id): m = Message.query.get(message_id) return render_template("messages/edit.html", form=MessageForm(name=m.content), message=Message.query.get(message_id))