def accept_blast(blast_id): blast = Blast.query.filter_by(id=blast_id, receiver=current_user.id).first() if not blast: flash('Invalid Blast selected') return redirect(url_for('index')) form = BookingForm() dog_name = blast.slot.subject.dog_name if form.validate_on_submit(): user_id = current_user # Update blast record blast.status = BOOKED # Update parent slot blast.slot.status = BOOKED blast.slot.booker = current_user blast.comments = form.comments.data db.session.commit() send_accepted_blast(blast) send_blast_fulfilled_email(blast.slot) return redirect(url_for('confirmed', slot=blast.slot.id)) return render_template('book_slot.html', title='Slot booked', slot=blast.slot, dog_name=dog_name, form=form)
def book(event_id): data = db.session.query(Event).join( Location, Location.id == Event.location_id).with_entities( Event.name, Event.capacity, Event.start, Event.end, Location.name.label('location_name'), Location.address, Event.img_name).filter(Event.id == event_id).first() ticket_amt = [(i, i) for i in range(1, data.capacity + 1)] form = BookingForm() form.amount.choices = ticket_amt if data is None: return render_template('error_event.html') if form.validate_on_submit(): event = Event.query.get(event_id) event.capacity -= form.amount.data booking = Booking(user_id=current_user.id, event_id=event_id, quantity=form.amount.data, book_time=datetime.utcnow(), last_modified=datetime.utcnow()) db.session.add(booking) db.session.commit() app.logger.info( 'User ID {} has booked {} tickets (Booking ID {}) for Event ID {} at {}.' .format(booking.user_id, booking.quantity, booking.id, booking.event_id, datetime.now())) flash( 'Successfully purchased {} tickets for {}'.format( form.amount.data, data.name), "info") return redirect(url_for('main_panel.events')) return render_template('book.html', event_id=event_id, data=data, form=form)
def booking(teacher_id, day, hour): form = BookingForm() if form.validate_on_submit(): bk = Booking(teacher_id=teacher_id, day=day, hour=hour) bk.student_name = form.contact_info.student_name.data bk.student_phone = form.contact_info.student_phone.data teacher = Teacher.query.get(teacher_id) teacher.set_hour_state(day, hour, False) # теперь время - занято bk.save() return render_template("done.html", title={ "label": "Тема", "value": "Пробный урок" }, time={ "label": days[bk.day], "value": f"{bk.hour}:00" }, name=bk.student_name, phone=bk.student_phone) return render_template("booking.html", teacher=Teacher.query.get(teacher_id), time={ "day": day, "hour": hour }, days=days, form=form)
def render_booking_done(): teacher = Teacher.query.filter( Teacher.id == int(request.form.get("clientTeacher"))).first() schedule = Schedule.query.filter( Schedule.id == int(request.form.get("schedule"))).first() form = BookingForm() if form.validate_on_submit(): name = form.clientName.data phone = form.clientPhone.data client = Client(name=name, phone=phone) db.session.add(client) # TODO # изменить ли структуру модели Client # так что бы хранил не id и ссылку # тогда можно без коммита db.session.commit() db.session.add( Booking(client=client.id, teacher=teacher.id, schedule=schedule.id)) db.session.commit() return render_template( "booking_done.html", name=name, phone=phone, day=ReadData.day_week.get(schedule.day_week, ""), time=schedule.time, ) else: return url_for("booking.html")
def index(): form = BookingForm() #Variabel för formen som finns i forms.py if form.validate_on_submit(): try: if int(form.tableInt.data) <= 47 and int( form.tableInt.data ) >= 1: #Verifierar att användaren inte tar något bordsnummer som inte finns i kartan table = Table( tableInt=int(form.tableInt.data), isBooked=True, username=current_user.username ) #Den här variabeln ger datan som sedan ska läggas till i databasen db.session.add(table) #Lägg till i databasen db.session.commit() #Uppdatera databasen med ny data flash('Du har nu bokat ett bord') ## Nu funkar allt bra else: ##om användaren skirver in t.ex. 56 kommer den här köras flash('Det finns ingen plats som heter så') except: #Om det blir helt fel, t.ex. om användaren skirver in bokstäver i formen, så hamnar man här, därför att formens data konverteras till int flash( 'Bokningen kunde inte slutföras, kolla att du inte tar en upptagen plats!' ) return redirect(url_for('index')) ##användaren skickas tll hemsidan tableInfo = Table.query.order_by( Table.tableInt).all() #variabel som har värderna i modelen Table return render_template( 'index.html', title='Home', form=form, tableInfo=tableInfo ) #visar hemsidan och skickar med information som kan användas med jinja2
def create_booking(): form = BookingForm() form['csrf_token'].data = request.cookies['csrf_token'] print() if form.validate_on_submit(): booking = Booking(book_date=form.data['book_date'], book_start_time=form.data['book_start_time'], book_end_time=form.data['book_end_time'], user_id=form.data['user_id'], service_id=form.data['service_id']) db.session.add(booking) db.session.commit() newbooking = Booking.query.filter_by(id=booking.id).join(Aircraft).one() return to_booking(newbooking)
def book_slot(): form = BookingForm() slot = request.args.get('slot') slot = Slot.query.filter_by(id=slot).first() dog_name = slot.subject.dog_name if form.validate_on_submit(): user_id = current_user slot.comments = form.comments.data db.session.commit() return redirect(url_for('confirmed', slot=slot.id)) return render_template('book_slot.html', title='Slot booked', slot=slot, dog_name=dog_name, form=form)
def booking(teacher_id): teacher = db.session.query(Teacher).get_or_404(teacher_id) form = BookingForm() if form.validate_on_submit(): weekday_ru = request.args.get('day') time = request.args.get('time') weekday_slug = next( (day_en for day_en, day_ru in RU_DAYS.items() if weekday_ru == day_ru), None ) booking = Booking( username=form.name.data, phone=form.phone.data, weekday=weekday_ru, time=time ) teacher_schedule = json.loads(teacher.schedule) teacher_schedule[weekday_slug][time] = False teacher.schedule = json.dumps(teacher_schedule) teacher.bookings.append(booking) db.session.add(teacher) db.session.add(booking) db.session.commit() context = { 'name': booking.username, 'phone': booking.phone, 'lesson_day': booking.weekday , 'lesson_time': booking.time, 'subject': 'trial', 'subject_description': 'Пробное занятие' } return redirect(url_for('sent', context=json.dumps(context))) context = { 'teacher': teacher, 'lesson_day': RU_DAYS[request.args.get('day')], 'lesson_time': request.args.get('time') } return render_template('booking.html', form=form, **context)
def book_car_request(id): form = BookingForm(date=date.today(), time=datetime.now() + timedelta(hours=1), car_id=id, user_id=current_user.id) if form.validate_on_submit(): time_start = datetime.combine(form.date.data, form.time.data) data = { 'user_id': form.user_id.data, 'car_id': form.car_id.data, 'time_start': time_start.isoformat(), 'hours': form.duration.data } r = requests.post('http://192.168.1.109:10100/book', json=data, verify=False) bookingData = r.json() r = requests.get('http://192.168.1.109:10100/cars/{}'.format( data['car_id']), verify=False) carData = r.json() if 'id' in bookingData: start = datetime.fromisoformat( bookingData['timestart']).strftime("%m/%d/%Y, %H:%M") flash('you booked {carname} for {hours} hours starting {start}'. format(carname=carData['name'], hours=bookingData['dration'], start=start)) return redirect(url_for('index')) else: flash("The {carname} has been booked, try book another one".format( carname=carData['name'])) return redirect(url_for('index')) return render_template('book.html', title='Make a Booking', form=form, id=id)