def before_request(): g.user = None g.rooms = None g.chats = None g.jchats = None g.others = None if 'uid' in session: g.user = User.query.filter_by(id=session['uid']).first() if g.user != None: g.rooms = Room.query.order_by(Room.lastmessage.asc()).all() if g.user.currentroom > 0: g.chats = Chat.query.filter(Chat.room == g.user.currentroom).order_by(Chat.created.asc()).all() g.jchats = Chat.as_json(g.user.currentroom) g.others = [u.username for u in User.query.filter(User.currentroom == g.user.currentroom).all()] else: g.chats = Chat.query.limit(10).all() g.jchats = Chat.as_json()
def get_chats(): if g.user: chatsJSON = Chat.as_json(g.user.currentroom) chats = len(chatsJSON) if chats == 0: flash("room no longer exists") return redirect(url_for("index")) else: return str(chats) else: abort(404)