def load_user_from_username_or_id(username: Union[str, int]): if not username.isdigit(): user = db.session.query(User).filter( db.and_(User.username == username, User.is_deleted == False)).first() else: user = db.session.query(User).filter( db.and_(User.id == username, User.is_deleted == False)).first() return user
def create_service_flows(ns_instance_id, n=4): service = Service.query.filter_by(ns_instance_id=ns_instance_id).first() switch = NFVI.query.filter_by(id=service.NFVI_id).first().switch of_table = 0 db.session.add(service) flows = [] of_id = db.session.query(db.func.max(Flow.of_id)).filter( db.and_(Flow.switch==switch, Flow.of_table==of_table)).scalar() if of_id is None: of_id = 0 for i in xrange(1,5): of_id += 1 flow = Flow(switch, of_table, of_id) db.session.add(flow) db.session.flush() flow_service = Flow_Service(flow.id, service.id) db.session.add(flow_service) db.session.flush() flows.append({ 'id' : flow.id, 'switch' : flow.switch, 'of_table' : flow.of_table, 'of_id': flow.of_id, }) db.session.commit() return flows
def api_v1_game_add(user): f_data = f.request.form name = f_data.get("game_name") platform = f_data.get("game_platform") if name is None: return f.jsonify({"result": "error", "reason": "Missing game_name."}) if platform is None: return f.jsonify({ "result": "error", "reason": "Missing game_platform." }) game = d.session.query(database.Game).filter( d.and_( d.func.lower(database.Game.name) == name.lower(), d.func.lower( database.Game.platform) == platform.lower())).one_or_none() if game is not None: return f.jsonify({ "result": "error", "reason": "Game already exists.", "game": game.json() }) game = database.Game(name=name, platform=platform) d.session.add(game) d.session.commit() return f.jsonify({ "result": "success", "description": "Game added.", "game": game.json() })
def load_user_from_request(request): api_key = request.args.get('api_key') or request.headers.get( 'Authorization') if api_key: user = db.session.query(User).filter( db.and_(User.api_key == api_key, User.is_deleted == False)).first() if user: return user
def post(request): request = request['service'] ns_instance_id = request['ns_instance_id'] client_mkt_id = request['client_mkt_id'] nap_id = NAP.query.filter_by(mkt_id=request['nap_mkt_id']).first().id nfvi_id = NFVI.query.filter_by(mkt_id=request['nfvi_mkt_id']).first().id switch = NFVI.query.filter_by(mkt_id=request['nfvi_mkt_id']).first().switch used_vlans = Vlan.query.join(Service, db.or_( Service.ce_transport_id == Vlan.id, Service.pe_transport_id == Vlan.id) ).join(NFVI, Service.NFVI_id == NFVI.id).filter( db.and_( db.or_(Service.status == 'ALLOCATED', Service.status == 'ACTIVE'), NFVI.switch==switch)).all() available_vlans = set(xrange(1, 4096)) vlans = available_vlans - set([vlan.vlan_id for vlan in used_vlans]) vlans = list(vlans) if len(vlans) > 1: vlans = vlans[0:2] status = 'ALLOCATED' ce_transport = Transport() pe_transport = Transport() db.session.add(ce_transport) db.session.add(pe_transport) db.session.flush() ce_vlan = Vlan(ce_transport.id, vlans[0]) pe_vlan = Vlan(pe_transport.id, vlans[1]) db.session.add(ce_vlan) db.session.add(pe_vlan) db.session.flush() service = Service(ns_instance_id, client_mkt_id, status, nap_id, nfvi_id, ce_transport.id, pe_transport.id) else: vlans = [] status = 'NOT AVAILABLE' service = Service(ns_instance_id, client_mkt_id, status, nap_id, nfvi_id, None, None) db.session.add(service) db.session.commit() return [int(x) for x in vlans[0:2]]
def openid_steam_login_successful(): user = f.session.get("user") steam_id = f.session.get("steam_id") if user is None: return f.jsonify({"result": "error", "reason": "Not logged in."}) if steam_id is None: return f.jsonify({"result": "error", "reason": "No steam login."}) games_data = steam_api.IPlayerService.GetOwnedGames_v1( steamid=steam_id, include_appinfo=True, include_played_free_games=True, appids_filter=None) # TODO: improve performance here for game in games_data["response"]["games"]: db_steamgame = d.session.query(database.SteamGame).filter_by( steam_app_id=game["appid"]).one_or_none() if db_steamgame is None: db_game = d.session.query(database.Game).filter( d.and_( d.func.lower(database.Game.name) == game["name"].lower(), database.Game.platform == "Steam")).one_or_none() if db_game is None: db_game = database.Game(name=game["name"], platform="Steam") d.session.add(db_game) db_steamgame = database.SteamGame(game=db_game, steam_app_id=game["appid"], steam_app_name=game["name"]) d.session.add(db_steamgame) copy = d.session.query(database.SteamGame) \ .filter_by(steam_app_id=game["appid"]) \ .join(database.Game) \ .join(database.Copy) \ .filter_by(owner_id=user["id"]) \ .first() if copy is not None: continue print(game["name"]) if game["playtime_forever"] > 0: play_status = None else: play_status = database.GameProgress.NOT_STARTED d.session.flush() copy = database.Copy(owner_id=user["id"], game_id=db_steamgame.game_id, progress=play_status) d.session.add(copy) d.session.commit() return f.redirect(f.session.get("openid_redirect_to"))
def viewReservation(admin): if request.method == 'POST': fromDate = request.form['fromDate'] toDate = request.form['toDate'] if (ifNone(toDate)): toDate = 100000000000 else: toDate = int(toDate) if (ifNone(fromDate)): fromDate = 0 else: fromDate = int(fromDate) query_c = db.session.query(Reservation, Camping).filter( Reservation.id == Camping.res_id, Reservation.deleted == False, Reservation.isCamping == 1, db.or_( db.and_(Camping.fromDate >= fromDate, Camping.fromDate <= toDate), db.and_(Camping.toDate >= fromDate, Camping.toDate <= toDate))).all() query_p = db.session.query(Reservation, Picnic).filter( Reservation.id == Picnic.res_id, Reservation.deleted == False, Reservation.isPicnic == 1, db.and_(Picnic.date >= fromDate, Picnic.date <= toDate)).all() query_r = db.session.query(Reservation, Resto).filter( Reservation.id == Resto.res_id, Reservation.deleted == False, Reservation.isResto == 1, db.and_(Resto.date >= fromDate, Resto.date <= toDate)).all() resp = [] for c in query_c: resp.append({ "id": c.Reservation.id, "name": c.Reservation.name, "phone": c.Reservation.phone, "numPeople": c.Reservation.numPeople, "moreInfo": c.Reservation.moreInfo, "type": "Camping", "added_date": c.Reservation.added_date, "added_by": c.Reservation.added_by, "fromDate": c.Camping.fromDate, "toDate": c.Camping.toDate, "withBBQ": c.Camping.withBBQ, "withTent": c.Camping.withTent, "withMatress": c.Camping.withMatress, "withFood": c.Camping.withFood, "table": c.Camping.table, "pricePerson": c.Camping.pricePerson }) for c in query_p: resp.append({ "id": c.Reservation.id, "name": c.Reservation.name, "phone": c.Reservation.phone, "numPeople": c.Reservation.numPeople, "moreInfo": c.Reservation.moreInfo, "type": "Picnic", "added_date": c.Reservation.added_date, "added_by": c.Reservation.added_by, "date": c.Picnic.date, "withBBQ": c.Picnic.withBBQ, "table": c.Picnic.table, "pricePerson": c.Picnic.pricePerson }) for c in query_r: resp.append({ "id": c.Reservation.id, "name": c.Reservation.name, "phone": c.Reservation.phone, "numPeople": c.Reservation.numPeople, "moreInfo": c.Reservation.moreInfo, "type": "Resto", "added_date": c.Reservation.added_date, "added_by": c.Reservation.added_by, "date": c.Resto.date, "table": c.Resto.table }) return jsonify(resp) return error("Send POST request")