def new_bike(): if request.method == 'GET': return render_template("bike.html") elif request.method == 'POST': form = request.form model = form['model'] fee = form['fee'] image = form['image'] year = form['year'] new_bike = Bike(model=model, fee=fee, image=image, year=year) new_bike.save() return redirect("/new_bike")
def home(): if request.method == 'GET': return render_template('new_bike_form.html') else: form = request.form model = form["model"] fee = form["fee"] image = form["image"] year = form["year"] bike_sample = Bike(model=model, fee=fee, image=image, year=year) bike_sample.save() return "Hurrayyy"
def newbike(): if request.method == "GET": return render_template("add_bike.html") elif request.method == "POST": form = request.form model = form["model"] daily = form["daily"] image = form["image"] year = form["year"] new_bike = Bike(model=model, daily=daily, image=image, year=year) new_bike.save() return ("hello")
def new_bike(): form = request.form if request.method == "GET": return render_template("bike.html") elif request.method == "POST": model = form["model"] daily_fee = form["daily_fee"] image = form["image"] year = form["year"] add_new_bike = Bike(model=model, daily_fee=daily_fee, image=image, year=year) add_new_bike.save() return "Save successfully"
def add_charactnew_bikeer(): #1: gửi form(GET) if request.method == "GET": return render_template("new_bike.html") elif request.method == "POST": #4: nhận form => Lưu (POST) form = request.form model = form["model"] fee = form["fee"] image = form["image"] year = form["year"] print(model, fee, image, year) new_bike = Bike(model=model, fee=fee, image=image, year=year) new_bike.save() return redirect("/new_bike")
def create_bike(): content = request.json if db.session.query(Bike).filter(Bike.bike_id == content.get( "bikeDetails", {}).get("bike_id")).first(): return jsonify({"error": {"bike_id": "already exists"}}) bike_details = content.get("bikeDetails") b = Bike( first_name=bike_details.get("firstName"), last_name=bike_details.get("lastName"), color=bike_details.get("color"), brand=bike_details.get("brand"), phone=bike_details.get("phone"), city=bike_details.get("city"), secondary_phone=bike_details.get("secondary_phone"), bike_id=bike_details.get("bike_id"), assets=json.dumps(bike_details.get("assets")), ) db.session.add(b) db.session.commit() bike = b res = dict( brand=bike.brand, color=bike.color, bike_id=bike.bike_id, firstName=bike.first_name, lastName=bike.last_name, city=bike.city, phone=bike.phone, secondary_phone=bike.secondary_phone, ) return jsonify({"success": True, "result": {"bike": res}})
def create_bike(): manufacturer = manufacturer_repository.select(request.form['manufacturer_id']) model = request.form['model'] description = request.form['description'] buy_cost = request.form['buy_cost'] sell_price = request.form['sell_price'] stock_level = request.form['stock_level'] bike = Bike(manufacturer, model, description, buy_cost, sell_price, stock_level) bike_repository.save(bike) return redirect('/bikes')
def update_bike(id): manufacturer = manufacturer_repository.select(request.form['manufacturer_id']) model = request.form['model'] description = request.form['description'] buy_cost = request.form['buy_cost'] sell_price = request.form['sell_price'] stock_level = request.form['stock_level'] update_mark_up = round((((float(sell_price) - float(buy_cost)) / float(buy_cost)) * 100), 2) bike = Bike(manufacturer, model, description, buy_cost, sell_price, stock_level, update_mark_up, id) bike_repository.update(bike) return redirect('/bikes')
def select(id): bike = None sql = "SELECT * FROM bikes WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: manufacturer = manufacturer_repository.select( result['manufacturer_id']) bike = Bike(manufacturer, result['model'], result['description'], result['buy_cost'], result['sell_price'], result['stock_level'], result['mark_up'], result['id']) return bike
def select_all(): bikes = [] sql = "SELECT * FROM bikes" results = run_sql(sql) for row in results: manufacturer = manufacturer_repository.select(row['manufacturer_id']) bike = Bike(manufacturer, row['model'], row['description'], row['buy_cost'], row['sell_price'], row['stock_level'], row['mark_up'], row['id']) bikes.append(bike) return bikes
def bikes(manufacturer): bikes = [] sql = "SELECT * FROM bikes WHERE manufacturer_id = %s" values = [manufacturer.id] results = run_sql(sql, values) for row in results: bike = Bike(row['manufacturer_id'], row['model'], row['description'], row['buy_cost'], row['sell_price'], row['stock_level'], row['mark_up'], row['id']) bikes.append(bike) return bikes
def generate_bikes(self, number): print("Generating bikes") for i in range(number): self.bikes.append(Bike(self.faker))
def test_bike_has_attributes(self): ''' Checks the bike attributes exist ''' new_bike = Bike() self.assertTrue('city_id' in new_bike.__dir__()) self.assertTrue('user_id' in new_bike.__dir__()) self.assertTrue('latitude' in new_bike.__dir__()) self.assertTrue('longitude' in new_bike.__dir__()) self.assertTrue('longitude' in new_bike.__dir__()) self.assertTrue('name' in new_bike.__dir__()) self.assertTrue('description' in new_bike.__dir__()) self.assertTrue('color' in new_bike.__dir__()) self.assertTrue('size' in new_bike.__dir__()) self.assertTrue('category_ids' in new_bike.__dir__()) self.assertTrue('price_per_day' in new_bike.__dir__())
def test_bike_inherits_from_base_model(self): ''' Checks that the Bike class Inherits from BaseModel ''' new_bike = Bike() self.assertIsInstance(new_bike, BaseModel)