Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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())
Esempio n. 4
0
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)
Esempio n. 5
0
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())
Esempio n. 6
0
def _name_in_use(form, field):
    if Chat.exists(field.data):
        raise ValidationError('Name in use')
Esempio n. 7
0
def chats_delete(chat_id):
    if not current_user.is_admin():
        abort(403)
    Chat.delete(chat_id)
    return redirect(url_for('chats_all'))
Esempio n. 8
0
def chats_all():
    if current_user.is_admin():
        return render_template("chats/all.html", chats=Chat.all())
    abort(403)