Exemple #1
0
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')
Exemple #2
0
def booking(teacher_id, day_of_week, time):

    day = days[day_of_week]
    teacher = db.session.query(Teacher).filter(
        Teacher.id == teacher_id).first()
    time = time.replace("-", ":")

    form = BookingForm()

    if form.validate_on_submit():

        name = form.name.data
        phone = form.phone.data
        day = form.day.data
        time = form.time.data
        teacher_id = form.teacher.data

        request_data = Booking(name=name,
                               phone=phone,
                               day=day,
                               time=time,
                               teacher_id=teacher_id)
        db.session.add(request_data)
        db.session.commit()
        return render_template("booking_done.html",
                               form=form,
                               name=name,
                               phone=phone,
                               day=day,
                               time=time)
    return render_template("booking.html",
                           teacher=teacher,
                           time=time,
                           day=day,
                           form=form)
def booking():
    form = BookingForm()
    if form.validate_on_submit():
        form.send()
        flash('Thanks for contacting us! We promise to get back to you soon.', 'booking')
        return redirect(url_for('booking'))
    return render_template('booking.html', title='Booking', form=form)
def render_booking(profile_id, weekday, time):
    profile = db.session.query(Teacher).get_or_404(profile_id)
    form = BookingForm()
    form.weekday.default = weekday
    form.time.default = time
    form.teacher.default = profile_id
    if request.method == "POST":
        if form.validate_on_submit():
            name = form.name.data
            time = form.time.data
            weekday = form.weekday.data
            teacher_id = form.teacher.data
            phone = form.phone.data
            teacher = db.session.query(Teacher).get_or_404(profile_id)
            booking = Booking(weekday=weekday,
                              time=time,
                              teacher=teacher,
                              teacher_id=teacher_id,
                              name=name,
                              phone=phone)
            db.session.add(booking)
            schedule = teacher.free
            schedule[weekday][time] = False
            teacher.free = schedule
            flag_modified(teacher, "free")
            db.session.commit()
            return render_template('booking_done.html', weekday=WEEKDAYS[weekday], time=time, name=name, phone=phone)
    return render_template('booking.html', profile=profile, weekday=WEEKDAYS[weekday], time=time, form=form)
Exemple #5
0
def render_booking(lesson_id):
    error = ''
    form = BookingForm()
    lesson_id = int(lesson_id)
    lesson = Lesson.query.get_or_404(lesson_id)
    week_day = lesson.day_name.day_name
    _time = lesson.time.get_str_time()
    teacher = lesson.teacher
    if not lesson.status:
        error = f'Извините, у {teacher.name}  в  {week_day.lower()} {_time} нет свободного времени, ' \
                f'пожалуйста выберите другое время'
    if request.method == 'POST' and form.validate_on_submit() and error == '':
        form.lesson_id.data = int(lesson_id)
        booking = Booking()
        form.populate_obj(booking)
        client_name, client_phone = form.client_name.data, form.client_phone.data
        lesson.status = False
        db.session.add_all([lesson, booking])
        db.session.commit()
        return render_template('booking_done.html',
                               week_day=week_day,
                               day_time=_time,
                               name=client_name,
                               phone=client_phone)
    form.lesson_id.data = str(lesson_id)
    return render_template('booking.html',
                           teacher=teacher,
                           lesson_id=lesson_id,
                           week_day=week_day,
                           day_time=_time,
                           error=error,
                           form=form)
Exemple #6
0
def car_booking(item_id):
    car = get_car(item_id)['Item']
    car['carid'] = int(car['carid'])
    booking_form = BookingForm()
    if booking_form.submit5.data and booking_form.validate_on_submit():
        if logged_in_user.username == '':
            return redirect(url_for('car_booking', item_id=item_id, msg="You must login first!"))
        result1 = request.form
        event = {
            'id': int(time.time()),
            'place': result1['place'],
            'pickup_date': result1['pick_up_date'],
            'days': result1['days'],
            'order_date': str(datetime.today()),
            'carid': car,
            'payment_type': result1['payment_type'],
            'username': logged_in_user.username,
        }
        resp = rent_car(event)
        if resp['success']:
            return redirect(url_for('past_bookings', msg=resp['message']))
        else:
            return redirect(url_for('past_bookings', msg=resp['message']))
    return render_template('car-booking.html', bookingform=booking_form, user=logged_in_user, car=car,
                           msg=request.args.get('msg'))
Exemple #7
0
def book_form(id, day, time):
    form = BookingForm()

    teacher = db.session.query(Teacher).filter(Teacher.id == int(id)).one()

    if form.validate_on_submit():
        name = form.name.data
        phone = form.phone.data
        day = form.day.data
        time = form.time.data
        id = form.id.data

        teacher = db.session.query(Teacher).filter(Teacher.id == int(id)).one()
        teacher.schedule[day][time] = False
        flag_modified(teacher, "schedule")
        new_booking = Booking(day=day,
                              time=time,
                              client_id=check_client(name, phone),
                              teacher_id=id)
        db.session.add(new_booking)
        db.session.commit()

        return render_template("booking_done.html",
                               name=name,
                               phone=phone,
                               day_name=days[day],
                               time=time)

    return render_template("booking.html",
                           form=form,
                           teacher=teacher,
                           day=day,
                           day_name=days[day],
                           time=time)
def bookingDetails(carId):
    """
    Routes user to the registration page.
    Args:
        carId(str): Car unique identifier
    Returns:
        HTML: Bookind details page.
    """
    form = BookingForm()
    if form.validate_on_submit():
        userBookingData = {
            "pickUpDate": form.pickup_date.data,
            "pickUpTime": form.pickup_time.data,
            "returnDate": form.return_date.data,
            "returnTime": form.return_time.data,
            "carID": carId,
            "username": flask.session["username"],
        }
        userBookingJSONData = json.dumps(userBookingData, cls=DateTimeEncoder)
        response = requests.post(flask.request.host_url + "/bookingDetails",
                                 json=userBookingJSONData)
        data = json.loads(response.text)
        if data["message"] == "Success":
            flask.flash(data["message"], "success")
        else:
            flask.flash(data["message"], "danger")
    return flask.render_template("bookingDetails.html", form=form)
Exemple #9
0
def save_booking():
    if request.method == 'POST':
        form = BookingForm()
        booking = Booking(weekday=form.clientWeekday.data,
                          time=form.clientTime.data,
                          teacher_id=form.clientTeacher.data,
                          name=form.clientName.data,
                          phone=form.clientPhone.data)
        if form.validate_on_submit():
            db.session.add(booking)
            db.session.commit()
            return render_template('booking_done.html',
                                   clientWeekday=booking.weekday,
                                   clientTime=booking.time,
                                   clientName=booking.name,
                                   clientPhone=booking.phone,
                                   week=WEEK)
        return render_template(
            'booking.html',
            form=form,
            name=db.session.query(Teacher).get(booking.teacher_id).name,
            day=booking.weekday,
            hour=booking.time,
            picture=db.session.query(Teacher).get(booking.teacher_id).picture,
            id=booking.teacher_id,
            week=WEEK)
Exemple #10
0
def add_booking():
    form = BookingForm()
    if form.validate_on_submit():
        start_date = request.form['start_date']
        end_date = request.form['end_date']
        name = request.form['name']
        email = request.form['email']
        write_csv_file(bookings_file_path, [start_date, end_date, name, email])
        return redirect(url_for('show_bookings'))
    return show_bookings(form)
Exemple #11
0
def book():
    form = BookingForm()
    if form.validate_on_submit():
        service_name = form.bookingName.data
        service_date = form.bookingDate.data
        return redirect(
            url_for('booktime',
                    service_name=service_name,
                    service_date=service_date))

    return render_template('book.html', title='Appointment booker', form=form)
def new_booking_1():
    form = BookingForm()
    if form.validate_on_submit():
        booking_details = extract_booking_details(form)
        create_calendar_reminders(booking_details)
        create_spreadsheet_entry(booking_details)
        email_guest_booking_confirmation(booking_details)
        store_booking_in_database(booking_details)
        flash("Booking made.")
        return redirect(url_for('homepage'))
    return render_template('new_booking_1.html',
                           form=form,
                           properties=settings.PROPERTIES)
Exemple #13
0
def cart_render():
    form = BookingForm()
    cart_items = {}
    total = 0

    if request.method == 'POST':
        if form.validate_on_submit():
            request_data = {
                'name': form.name.data,
                'address': form.address.data,
                'email': form.email.data,
                'phone': form.phone.data,
                'order_summ': form.order_summ.data,
                'order_cart': form.order_cart.data
            }

            request_to_db = Order(date=(strftime("%Y-%m-%d %H:%M", gmtime())),
                                  total=request_data['order_summ'],
                                  status='Pending',
                                  phone=request_data['phone'],
                                  address=request_data['address'],
                                  user_id=current_user.id)

            db.session.add(request_to_db)

            for i in request_data['order_cart'][1:-1].split(','):
                meal = db.session.query(Meal).get(int(i))
                request_to_db.meals_list.append(meal)

            db.session.commit()
            session['order'] = request_to_db.id
            session.pop('cart')
            return redirect(url_for('cart.ordered_render'))

    if not session.get('cart') is None:
        cart = db.session.query(Meal).filter(Meal.id.in_(session['cart']))

        for id in session['cart']:
            item = cart.filter(Meal.id == id).first()
            total += item.price
            if not id in cart_items:
                cart_items[item.id] = [item.title, item.price, 1]
            else:
                cart_items[item.id][2] += 1

    final_total = lambda sum: str(f'{sum:,}').replace(',', ' ')
    return render_template('cart.html',
                           form=form,
                           cart_items=cart_items,
                           total=total,
                           total_cool=final_total(total))
Exemple #14
0
def modify_booking(item_id):
    booking = get_booking_by_id(item_id)
    booking_form = BookingForm(place=booking['place'], pick_up_date=booking['pickup_date'], days=booking['days'],
                               payment_type=booking['payment_type'])
    if booking_form.submit5.data and booking_form.validate_on_submit():
        if logged_in_user.username == "":
            return redirect(url_for('modify_booking', msg="You must be logged in modify the booking."))
        result1 = request.form
        resp = update_booking(item_id, result1['place'], result1['days'], result1['pick_up_date'])
        if resp['ResponseMetadata']['HTTPStatusCode'] == 200:
            return redirect(url_for('past_bookings'))
        else:
            return redirect(url_for('modify_booking', msg="Something went wrong."))
    return render_template('modify-booking.html', bookingform=booking_form, booking=booking, user=logged_in_user,
                           msg=request.args.get('msg'))
Exemple #15
0
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')
Exemple #16
0
def render_booking_item(teacher_id, weekday, time):
    teacher = Teacher.query.get(teacher_id)

    form = BookingForm()
    if request.method == "POST":
        # если данные post и get отличаются, приводим их к одному виду
        time = form.clientTime.data
        teacher_id = int(form.clientTeacher.data)
        weekday = form.clientWeekday.data

    day = next((w for w in WEEKDAYS if w[0] == weekday), -1)  #

    # Если данные были отправлены
    if request.method == "POST":
        if form.validate_on_submit():
            # получаем данные
            client_name = form.clientName.data
            client_phone = form.clientPhone.data

            # TODO Зачем нужен back_populates ведь в этом случае все работало бы и без него
            booking = Booking(name=client_name,
                              phone=client_phone,
                              teacher_id=teacher_id,
                              weekday=weekday,
                              time=time)
            db.session.add(booking)
            db.session.commit()

            # переходим на booking_done
            return render_template('booking_done.html',
                                   clientName=client_name,
                                   clientPhone=client_phone,
                                   clientWeekday=day,
                                   clientTime=time)

    # Если данные еще НЕ были отправлены или неверны
    # выводим форму
    form.clientTime.data = time
    form.clientTeacher.data = teacher_id
    form.clientWeekday.data = weekday

    return render_template('booking.html',
                           form=form,
                           t=teacher,
                           weekday=day,
                           time=time)
Exemple #17
0
def addbooking(id):
    #TODO: check that gite id belongs to user

    form = BookingForm ()
    uid = g.user.id
    form.customer.choices = [(c.id, c.name)for c in Customer.query.filter_by(user = uid).all()]
    if form.validate_on_submit():
        booking = Booking(start = form.start.data,
                          end = form.end.data,
                          gite_id = id,
                          customer_id = form.customer.data)
        db.session.add(booking)
        db.session.commit()
        flash("booking  rajoute!")
        return redirect(url_for('index'))

    return render_template('editbooking.html', form = form)
Exemple #18
0
def tutor_booking_page(tutor_id_name, day_time, schedule_id):
    tutor_id, tutor_name = tutor_id_name.split('--')
    day, time = day_time.split('--')
    form_booking = BookingForm()
    if form_booking.validate_on_submit():
        booking_client_name = form_booking.booking_client_name.data
        booking_client_tel = form_booking.booking_client_tel.data
        booking_tutor_id = form_booking.booking_tutor_id.data
        booking_tutor_name = form_booking.booking_tutor_name.data
        booking_day = form_booking.booking_day.data
        booking_time = form_booking.booking_time.data
        booking_new = Booking(name=booking_client_name, phone=booking_client_tel, schedule_id=schedule_id)
        db.session.add(booking_new)
        db.session.commit()
        return redirect(url_for('search_result_page'))

    booking_data = {'tutor_id': tutor_id, 'tutor_name': tutor_name, 'day': day, 'time': time}
    return render_template('booking.html', booking_data=booking_data, form_booking=form_booking)
Exemple #19
0
def booking(uid, date_str, time_str):
    resource = User.getByUrlsafeId(uid)
    tz = resource.getTimezoneObject()
    duration = resource.prefs.duration
    dt_str = '%s %s' % (date_str, time_str.replace('-', ':', 1))
    dt_start = tz.localize(date_parser.parse(dt_str))
    dt_end = dt_start + timedelta(minutes=duration)
    form = BookingForm(start_time=dt_start, end_time=dt_end, timezone=tz.zone)
    if request.method == 'POST':
        if form.validate_on_submit():
            booking = Booking.createFromPost(resource, form.data)
            flash('Your booking succeeded.', 'info')
            return redirect(url_for('calendar', uid=uid, date_str=date_str))
        else:
            flash_form_errors('Your booking failed.', form)
    return render_template('booking-new.html', 
        uid=uid, date_str=date_str, time_str=time_str, 
        form=form, resource=resource, 
        dt_start=dt_start, tz=tz, duration=duration)
def render_booking(id_teacher, week_day, time):
    teacher = Teacher(id_teacher)
    teacher_data = teacher.teacher_data_generator()
    form = BookingForm()
    form.weekday.data = week_day
    form.time.data = time
    form.teacher.data = id_teacher
    if form.validate_on_submit():
        teacher.teacher_change_schedule(id_teacher, week_day, time,
                                        form.name.data, form.phone.data)
        user_data = f'?id={id_teacher}&wd={week_day}&t={time}&n={form.name.data}&p={form.phone.data}'

        return redirect('/booking_done/' + user_data, code=302)
    else:
        return render_template('booking.html',
                               teacher_data=teacher_data,
                               week_day=week_day,
                               time=time,
                               form=form)
Exemple #21
0
def render_booking_done():
    if request.method == "GET":
        return redirect("/")
    form = BookingForm()
    if form.validate_on_submit():
        day = form.clientWeekday.data
        time = form.clientTime.data
        teacher = db.session.query(Teacher).get((int(form.clientTeacher.data)))
        name = form.clientName.data
        phone = form.clientPhone.data
        s.booking_successful(teacher, day, time, name, phone)
        return render_template("booking_done.html",
                               day=days[day],
                               time=time,
                               teacher_picture=teacher.picture,
                               name=name,
                               phone=phone,
                               title="Заявка успешно отправлена")
    return redirect(form.url.data)
Exemple #22
0
def new_booking():
    if not current_user.is_authenticated:
        return redirect(url_for('core.home'))

    form = BookingForm()
    if form.validate_on_submit():
        print(form.car_id.data)
        booking = Booking(user_id=current_user.id,
                          car_id=form.car_id.data,
                          start_time=form.start_date_time.data,
                          end_time=form.end_date_time.data)
        booking_validation = booking.is_car_avaiable()
        if booking_validation['result'] == False:
            flash(booking_validation['reason'])
            return render_template('booking/new.html',
                                   title='New Booking',
                                   form=form)
        db.session.add(booking)
        db.session.commit()
        flash('Thanks for making a booking')
        return redirect(url_for('booking_blueprint.bookings'))
    return render_template('booking/new.html', title='New Booking', form=form)