def booking(): form = BookingForm() form.carnumber.data = request.args['carnumber'] form.user.data = request.args['user'] #form.start_date.data=date.today() #form.end_date.data=date.today() form.number_of_days.data='0' form.cost.data='0' if ((form.validate_on_submit()==True)): form.start_date.data=form.start_date.data form.end_date.data=form.end_date.data form.number_of_days.data = form.setnod(form.start_date,form.end_date).days+1 car = Car.query.filter_by(carnumber=form.carnumber.data).first() price = car.cost_per_hour form.cost.data = form.setcost(form.number_of_days, price) flash('Booking confirmed!', 'success') bid = form.carnumber.data + datetime.strftime(form.start_date.data, '%m/%d/%Y') booking = Booking(booking_id = bid,carnumber = form.carnumber.data,user = form.user.data,start_date = form.start_date.data, end_date = form.end_date.data,start_location = car.location, end_location = None, number_of_days = form.number_of_days.data, cost = form.cost.data) bdb.session.add(booking) car.isAvailable = False cdb.session.commit() bdb.session.commit() print("returning true") return render_template('booking.html', form=form, user = request.args['user'], disabled='true') return render_template('booking.html', form=form, user = request.args['user'], disabled = 'false')
def booking(): form = BookingForm() form.carnumber.data = request.args['carnumber'] form.user.data = request.args['user'] form.number_of_days.data = '0' form.cost.data = '0' service = build("calendar", "v3", http=Http()) if ((form.validate_on_submit() == True)): form.start_date.data = form.start_date.data form.end_date.data = form.end_date.data form.number_of_days.data = form.setnod(form.start_date, form.end_date).days + 1 car = Car.query.filter_by(carnumber=form.carnumber.data).first() price = car.cost_per_hour form.cost.data = form.setcost(form.number_of_days, price) flash('Booking confirmed!', 'success') bid = form.carnumber.data + datetime.strftime(form.start_date.data, '%m/%d/%Y') booking = Booking(booking_id=bid, carnumber=form.carnumber.data, user=form.user.data, start_date=form.start_date.data, end_date=form.end_date.data, start_location=car.location, end_location=None, number_of_days=form.number_of_days.data, status=True, cost=form.cost.data, event_id=None) bdb.session.add(booking) eid = booking.addToCalendar(service) eid = eid.split("?eid=", 1) eveid = eid[1] booking.event_id = eveid car.isAvailable = False cdb.session.commit() bdb.session.commit() print("returning true") return render_template('booking.html', form=form, user=request.args['user'], disabled='true') return render_template('booking.html', form=form, user=request.args['user'], disabled='false')