def show_route_stops(route_id): """ List all stops on route. """ # TODO: add pagination cache_key = f'route_{route_id}' routes = redis.get('routes') if not routes: routes = transport.get_all_routes() # cache redis.set('routes', json.dumps(routes)) else: routes = json.loads(routes.decode()) route = routes.get(route_id) if cache_key.encode() in redis.keys(): route_stops = json.loads(redis.get(cache_key).decode()) else: route_stops = transport.get_route_stops(route_id) # store to cache redis.set(cache_key, json.dumps(route_stops)) if current_user.is_authenticated: user_stops = [stop.code for stop in current_user.stops] else: user_stops = list() return render_template('route_stops.html', route=route, stops=route_stops, user_stops=user_stops)
def session_check(text=None): sid = request.cookies.get('sid', None) user = User.get_by_login('qwe') uid = user and user.id or None if sid and uid: session = {'user': {'id': uid}} redis.set(sid, pickle.dumps(session)) return True
def logout(): sid = request.cookies.get('sid', None) session = redis.get(sid) if session is not None: session = pickle.loads(session) user = session.get('user', None) if user: user['id'] = None redis.set(sid, pickle.dumps(session))
def login(login, password): if ldap.bind_user(login, password): sid = request.cookies.get('sid', None) user = User.get_by_login(login) uid = user and user.id or None if sid and uid: session = { 'create_datetime': datetime.datetime.now().isoformat(), 'user': {'id': uid} } redis.set(sid, pickle.dumps(session)) return True return False
def login(login, password): if ldap.bind_user(login, password): sid = request.cookies.get('sid', None) user = User.get_by_login(login) uid = user and user.id or None if sid and uid: session = { 'create_datetime': datetime.datetime.now().isoformat(), 'user': { 'id': uid } } redis.set(sid, pickle.dumps(session)) return True return False
def show_all_routes(): """ List all routes. """ # TODO: add pagination routes = redis.get('routes') if not routes: routes = transport.get_all_routes() # cache redis.set('routes', json.dumps(routes)) else: routes = json.loads(routes.decode()) return render_template('routes.html', routes=routes)
def monitor_stop(stop_code): """ Get info about certain stop. """ stops = redis.get('stops') if not stops: stops = transport.get_all_stops() redis.set('stops', json.dumps(stops)) else: stops = json.loads(stops.decode()) stop = stops.get(stop_code) stop_info = transport.monitor_stop(stop_code) return render_template('stop_info.html', stop=stop, stop_info=stop_info)
def user_log(room, uid, content): query = {"_id": room} user = User.query.get(uid) if user is None: message = { "errno": status.CODE_NO_USER, "errmsg": errmsg.user_not_exists, } socketio.emit("login_response", message, namespace="/mofang", room=room) return name = user.nickname if user.nickname else user.name message = { "uid": user.id, "sid": request.sid, "user": name, "avatar": user.avatar if user.avatar else current_app.config["DEFAULT_AVATAR"], 'created_time': int(datetime.now().timestamp()), } if "%s" in content: message["log"] = content % name else: message["message"] = content chat_list = mongo.db.user_chat_list.find_one(query) if not chat_list: mongo.db.user_chat_list.insert_one(query, {"stream_name": room}) key = "%s_%s" % (room, request.sid) print(key) redis.set(key, user.id) mongo.db.user_chat_list.update_one(query, {"$push": { "message_list": message }}) return message
def show_all_stops(): """ List all stops. """ # TODO: add pagination stops = redis.get('stops') if not stops: stops = transport.get_all_stops() redis.set('stops', json.dumps(stops)) else: stops = json.loads(stops.decode()) if current_user.is_authenticated: user_stops = [stop.code for stop in current_user.stops] else: user_stops = list() return render_template('stops.html', stops=stops, user_stops=user_stops)
def translate_video_title(what): to_language = g.lang_code if to_language == "en": return what key = "{0}_{1}".format(what, to_language) translation = redis.get(key) if translation: return translation translator = Translator(to_lang=to_language) try: translation = translator.translate(what) redis.set(key, translation) except: translation = what return translation
def touch(sid, session): session['touch_datetime'] = datetime.datetime.now().isoformat() redis.set(sid, pickle.dumps(session))
def delete(self): jti = get_raw_jwt()["jti"] redis.set(jti, "true", app.config["JWT_ACCESS_TOKEN_EXPIRES"] * 1.2) return {"message": "Access token revoked successfully"}