def chats_create(): form = ChatForm() if form.validate_on_submit(): chat = Chat.create(form.name.data) ChatUser.create(current_user.id, chat.id, True) return redirect("/chats/" + str(chat.id)) return render_template("/chats/new.html", form=form)
def messages_view(message_id): message = Message.get(message_id) cu = ChatUser.get(message.chat_user_id) chat = Chat.get(cu.chat_id) user = User.find_id(cu.user_id) return render_template("messages/view.html", chat=chat, user=user, message=message)
def chats_management(chat_id): if not _member_of(current_user.id, chat_id): abort(403) chat = Chat.get(chat_id) users = User.find_members(chat_id) return render_template("chats/management.html", users=users, chat=chat, form=AddUserForm())
def users_view(user_id): user = User.find_id(user_id) if user is None: abort(404) chats = Chat.find_by_user(user_id) messages = Message.find_by_user(user_id) return render_template("users/view.html", user=user, chats=chats, messages=messages)
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 _name_in_use(form, field): if Chat.exists(field.data): raise ValidationError('Name in use')
def chats_delete(chat_id): if not current_user.is_admin(): abort(403) Chat.delete(chat_id) return redirect(url_for('chats_all'))
def chats_all(): if current_user.is_admin(): return render_template("chats/all.html", chats=Chat.all()) abort(403)