Beispiel #1
0
def get_booking(token):
    user = User.api_authenticate(token)
    if user:
        output = Booking.get_booking(user.pk)
        results = Booking.all_bookings()
        if output:
            return jsonify({"bookings":output,"results":results})
    return jsonify({"error":"failed"})
Beispiel #2
0
def update_booking(token,pk):
    user = User.api_authenticate(token)
    if user:
        output = request.get_json()
        data = Booking.all_bookings_pk(pk)
        output = Booking(output['pk'],data.first_name,output['date_stamp'],output['time_stamp'],output['full_date'],data.users_pk)
        output.save()
        return jsonify({"booking":output.date_stamp})
    return jsonify({"error":"failed"})
Beispiel #3
0
def booking(token):
    user = User.api_authenticate(token)
    if user:
        data = request.get_json()
        date = request.get_json()['date_stamp']
        time = request.get_json()['time_stamp']
        full = request.get_json()['full_date']
        new_booking = Booking(None,user.first_name,date,time,full,user.pk)
        if new_booking:
           new_booking.save()
        return jsonify({"booking":new_booking.time_stamp})
    return jsonify({"error":"failed"})
Beispiel #4
0
def delete_booking(token):
    data = request.get_json()
    if data:
        pk = data['pk']
        output = Booking.remove_booking(pk)
        return jsonify({"message":"success"})
    return jsonify({"message":"failed"})
Beispiel #5
0
def render_booking(teacher_id=None, day_of_week=None, time_booking=None):
    form = BookingToTeacher()
    if form.validate_on_submit():
        print("booking.validate_on_submit()")
        days = dict([(day_rus_eng[1], [day_rus_eng[0], day_eng])
                     for day_eng, day_rus_eng in days_of_week.items()])
        day = days[form.weekday.data][0]
        time = form.time.data + ":00"
        name = form.name.data
        phone = form.phone.data
        booking_param = [day, time, name, phone]
        db.session.add(
            Booking(
                learner=name,
                phone=phone,
                weekday=db.session.query(WeekDay).filter(
                    WeekDay.name_english_long == day_of_week).scalar(),
                time=time,
                teacher=db.session.query(Teacher).get(teacher_id),
            ))
        db.session.commit()
        return render_template('booking_done.html',
                               booking_param=booking_param)
    teacher_query = db.session.query(Teacher).get_or_404(
        teacher_id, description='Неверно указан код преподавателя')
    days = dict(
        (day_eng, day_rus) for day_rus, day_eng in days_of_week.values())
    if request.method == "GET" and (
        (day_of_week not in days.keys()) or not free_time_exist(
            teacher_id, day_of_week, time_booking + ":00")):
        return render_template(
            'str_404.html',
            error='Неверно указаны день недели или время бронирования'), 404
    day_booking = [days[day_of_week], day_of_week]
    form.weekday.data = day_of_week
    form.time.data = time_booking
    form.teacher.data = str(teacher_id)
    return render_template('booking.html',
                           teacher=teacher_query,
                           day_booking=day_booking,
                           form=form)
Beispiel #6
0
    db.session.add(a1)

    e1 = Enquiry(1, "Kochi", "Kerala", "Mangalapuram", "Karnatka",
                 "Calcium Carbide", "<9 Tonnes", "Lorry",
                 datetime.datetime.strptime("03/08/2016", '%d/%m/%Y'))
    e2 = Enquiry(2, "Mangalapuram", "Karnatka", "Kochi", "Kerala",
                 "Calcium Carbide", "<9 Tonnes", "Lorry",
                 datetime.datetime.strptime("03/08/2016", '%d/%m/%Y'))
    db.session.add(e1)
    db.session.add(e2)

    eq1 = Quote(1, 1, 18000)
    eq2 = Quote(1, 1, 27500)
    eq3 = Quote(1, 1, 37990)
    eq4 = Quote(1, 1, 48450)
    db.session.add(eq1)
    db.session.add(eq2)
    db.session.add(eq3)
    db.session.add(eq4)

    av1 = AssignedVehicle(1, "KA26C2355", "8281920566", "Hanjjjim",
                          "51/6564/karna", "", "0359")
    db.session.add(av1)

    b1 = Booking(1, 1, 1, "Kochi", "Kerala", "Mangalapuram", "Karnatka",
                 "Calcium Carbide", "<9 Tonnes",
                 datetime.datetime.strptime("03/08/2016", '%d/%m/%Y'))
    db.session.add(b1)

    db.session.commit()
db.session.query(Tutor).delete()
db.session.add_all(tutors_data_db_list)
# db.session.rollback()
db.session.commit()

for t in db.session.query(Tutor).all():
    print(t.goals)

for t in db.session.query(Tutor).filter(Tutor.goals.contains('work')).all():
    print(t.goals)


from app import Booking
booking = Booking(
    student_name='Me',
    phone_number='+7909898',
    day_of_week='mon',
    tutor_id=123,
)
db.session.add(booking)
db.session.commit()

for t in db.session.query(Booking).all():
    print(t.tutor_id, t.id, t.time, t.student_name, t.day_of_week)

from app import Application
for t in db.session.query(Application).all():
    print(t, 1, t.student_name)

Application.__table__.drop(db.engine)
db.session.query("drop table applicationsasfasf")
db.session.commit()