Exemple #1
0
def process():
    # pulls the form information from the post query
    form = request.form
    user = User.load_from_db_by_student_id(form["student_id"])
    # if the user doesn't exist in the database already, then creates a new user
    # users are classified by student id
    if not user:
        user = User(form["first_name"], form["last_name"], form["student_id"],
                    None)
        user.save_to_db()
        user = User.load_from_db_by_student_id(form["student_id"])
    # compiles a list of the seats chosen in the form from the post query
    seats = ""
    seat_list = form.getlist('seats')
    for seat in seat_list:
        seats += seat + " "
        new_seat = Seat(seat, form["screening"], None)
        new_seat.save_to_db()
    # updates attending in the screening database, then creates a new order in the database. all the fields that are
    # passed as None are filled by the database itself.
    Screening.update_attending(len(seat_list), form["screening"])
    new_order = Order(None, user.id, seats, form["screening"], None, None)
    new_order.save_to_db()
    new_order = Order.load_from_db_by_user_id(user.id)
    screening = Screening.load_from_db_by_screening_id(new_order.screening_id)
    movie = Movie.load_from_db_by_id(screening.movie_id)
    order_date = new_order.order_date.strftime("%B %d, %Y %I:%M %p")
    screening_date = screening.date.strftime("%B %d, %Y %I:%M %p")
    return render_template('orderdetails.html',
                           user=user,
                           order=new_order,
                           movie=movie,
                           screening=screening,
                           order_date=order_date,
                           screening_date=screening_date)