def new_reserv_page(): """ new_reserv_page(): This functions perform the actual booking process. If new_guest is set to TRUE, it also write a new entry in the guest's table to record the new user. This function returns many reservationIDs as the number of rooms booked and show them to the receptionist. It also sends a mail to the guest's email address with the reservation details. """ if not session.get('logged_in'): abort(401) template = env.get_template("confirm.html") mappa = {} values = [] for item in [ "name", "surname", "email", "passport", "address", "phone", "info" ]: values.append(request.form[item]) # values = [request.form[item] for item in ["name", "surname", "email", "passport", "address", "phone", "info"]] mappa["guest"] = values if request.form["new_guest"]: add = add_generic("guests") result = add(values) reserv = [] id_rooms = request.form["rooms"].split(",") id_rooms.pop() price = 0 for room in id_rooms: values = [] price = price + (int(request.form["checkout"]) - int(request.form["checkin"])) * (get_item( "rooms", "id_room", room)[0][3]) values.append(room) for item in ["id_guest", "checkin", "checkout"]: values.append(request.form[item]) add = add_generic("reservations") result = add(values) if not result: mappa[ "msg"] = "An error occured while creating the new reservation. Please check what's recorded in the system, in order to spot mistakes in the database's content." mappa["error"] = "TRUE" values.append( result ) #NB: in this way the id of the reservation is the LAST ELEMENT! reserv.append( values ) # "values" has the following structure: id_room - id_guest - checkin - checkout - id_res mappa["reserv"] = reserv mappa["price"] = price mappa["ckin"] = dataINT_to_datatime(int(request.form["checkin"])) mappa["ckout"] = dataINT_to_datatime(int(request.form["checkout"])) mappa["plural"] = "FALSE" print mappa if len(reserv) > 1: mappa["plural"] = "TRUE" return template.render(mappa)
def new_reserv_page(): """ new_reserv_page(): This functions perform the actual booking process. If new_guest is set to TRUE, it also write a new entry in the guest's table to record the new user. This function returns many reservationIDs as the number of rooms booked and show them to the receptionist. It also sends a mail to the guest's email address with the reservation details. """ if not session.get('logged_in'): abort(401) template = env.get_template("confirm.html") mappa = {} values = [] for item in ["name", "surname", "email", "passport", "address", "phone", "info"]: values.append(request.form[item]) # values = [request.form[item] for item in ["name", "surname", "email", "passport", "address", "phone", "info"]] mappa["guest"] = values if request.form["new_guest"]: add = add_generic("guests") result = add(values) reserv = [] id_rooms = request.form["rooms"].split(",") id_rooms.pop() price = 0 for room in id_rooms: values = [] price = price + (int(request.form["checkout"])-int(request.form["checkin"]))*(get_item("rooms", "id_room", room)[0][3]) values.append(room) for item in ["id_guest", "checkin", "checkout"]: values.append(request.form[item]) add = add_generic("reservations") result = add(values) if not result: mappa["msg"]="An error occured while creating the new reservation. Please check what's recorded in the system, in order to spot mistakes in the database's content." mappa["error"]="TRUE" values.append(result) #NB: in this way the id of the reservation is the LAST ELEMENT! reserv.append(values) # "values" has the following structure: id_room - id_guest - checkin - checkout - id_res mappa["reserv"] = reserv mappa["price"] = price mappa["ckin"] = dataINT_to_datatime(int(request.form["checkin"])) mappa["ckout"] = dataINT_to_datatime(int(request.form["checkout"])) mappa["plural"] = "FALSE" print mappa if len(reserv) > 1: mappa["plural"] = "TRUE" return template.render(mappa)
def checkout(): if not session.get('logged_in') or sudo() == "FALSE": abort(401) today = dataINT() template = env.get_template("manager.html") mappa = {"lista": list(guest_leaving(today))} mappa["username"] = session["username"] mappa["today"] = dataINT_to_datatime(today) return template.render(mappa)
def checkout(): if not session.get('logged_in') or sudo() == "FALSE": abort(401) today = dataINT() template = env.get_template("manager.html") mappa= {"lista" : list(guest_leaving(today))} mappa["username"] = session["username"] mappa["today"] = dataINT_to_datatime(today) return template.render(mappa)
def free_rooms_page(): """ free_rooms() In this page are shown a list of available rooms in a certain period of time and a form that the receptionist have to fill with the guest's data. From this interface the user can choose which room to book and select it. He can also insert the informations about the client, that will be used by the next functions before performing the actual booking process. """ if not session.get('logged_in'): abort(401) today = dataINT() cin = datepick_to_dataINT(request.args["checkin"]) cout = datepick_to_dataINT(request.args["checkout"]) mappa = {"nrooms": n_freerooms(cin, cout), "rooms" : sorted(free_rooms(cin, cout)), "checkin" : cin, "checkout" : cout, "ckin" : dataINT_to_datatime(cin), "ckout" : dataINT_to_datatime(cout) } template = env.get_template("booking.html") return template.render(mappa)
def free_rooms_page(): """ free_rooms() In this page are shown a list of available rooms in a certain period of time and a form that the receptionist have to fill with the guest's data. From this interface the user can choose which room to book and select it. He can also insert the informations about the client, that will be used by the next functions before performing the actual booking process. """ if not session.get('logged_in'): abort(401) today = dataINT() cin = datepick_to_dataINT(request.args["checkin"]) cout = datepick_to_dataINT(request.args["checkout"]) mappa = { "nrooms": n_freerooms(cin, cout), "rooms": sorted(free_rooms(cin, cout)), "checkin": cin, "checkout": cout, "ckin": dataINT_to_datatime(cin), "ckout": dataINT_to_datatime(cout) } template = env.get_template("booking.html") return template.render(mappa)
def main(): """ main() This function retrieves only the data shown in the upper div of the mainpage and renders it. From here the user can call 3 pages: free_rooms() (to begin the reservation process), reservations() (to search for present reservations), guests() (to search for registered guests). """ if not session.get('logged_in'): abort(401) today = dataINT() mappa = { "today" : dataINT_to_datatime(today), "n_checkin" : n_checkin(today), "n_checkout" : n_checkout(today), "n_occupate" : n_fullrooms(today, today), "n_libere" : n_freerooms(today, today)} if n_freerooms(today, today) < 0: mappa["msg"]= "Error: the number of today's reservations exceed the total number of rooms. Check the database!" #Keep this IF... mappa["error"] = "TRUE" template = env.get_template("main.html") return template.render(mappa)
def main(): """ main() This function retrieves only the data shown in the upper div of the mainpage and renders it. From here the user can call 3 pages: free_rooms() (to begin the reservation process), reservations() (to search for present reservations), guests() (to search for registered guests). """ if not session.get('logged_in'): abort(401) today = dataINT() mappa = { "today": dataINT_to_datatime(today), "n_checkin": n_checkin(today), "n_checkout": n_checkout(today), "n_occupate": n_fullrooms(today, today), "n_libere": n_freerooms(today, today) } if n_freerooms(today, today) < 0: mappa[ "msg"] = "Error: the number of today's reservations exceed the total number of rooms. Check the database!" #Keep this IF... mappa["error"] = "TRUE" template = env.get_template("main.html") return template.render(mappa)
def confirm(checkin, checkout): """ confirm() This page shows a sum-up of all the information inserted by the receptionist. Guest's data goes through some preprocessing before being shown: it's processed by matching_guest() in order to find if the guest has already been registered in the database. Four cases can be distinguished: - matching_guest() found only one perfectly matching row in the database. In this case the infos shown are the ones found in the database. - matching_guest() found no perfectly matching rows in the database. - matching_guest() found one partial match. in this case the receptionist is asked to modify the database in order to update guest's data, instead than inserting a new entry. - matching_guest() found more than one partial match. In this case The receptionist is asked to choose the guest between the partial matching ones and modify it, or to insert a completely new entry. - matching_guest() found no matching rows. In this case the data shown are the one the receptionist entered before. matching_guest() permits to distinguish between "completely matching" and "partially matching". - Perfectly matching: all the fields matches, notes excluded. - Partially matching: name, surname, passport matches. """ if not session.get('logged_in'): abort(401) mappa = { "ckin": dataINT_to_datatime(int(checkin)), "ckout": dataINT_to_datatime(int(checkout)) } sel_rooms = [] for room in free_rooms(checkin, checkout): if request.args.get(str(room[0])) == "on": sel_rooms.append(room) mappa["rooms"] = sel_rooms #Temo calcoli il prezzo sbagliato!! ************************************* <------------------ price = 0 for room in sel_rooms: price = price + price_from_room_id( room[0]) * (int(checkout) - int(checkin)) mappa["price"] = price guest = [] keys = [] match = [] mappa["error"] = "FALSE" for item in [ "name", "surname", "email", "passport", "phone", "address", "notes" ]: if request.args[item] != "": guest.append(request.args[item]) keys.append(item) match = matching_guest(keys, guest) if not match: for item in ["name", "surname", "passport"]: if request.args[item] != "": guest.append(request.args[item]) keys.append(item) match = matching_guest(keys, guest) if not match: g = [] g.append(n_items("guests", "", "") + 1) #The new ID for item in [ "name", "surname", "email", "passport", "phone", "address", "notes" ]: g.append(request.args[item]) if not request.args[item]: g.append("") if g[1] == "" or g[2] == "" or g[4] == "": mappa[ "msg"] = "You must insert name, surname, and passport No of the guest." mappa["error"] = "TRUE" match.append(g) mappa["new_guest"] = "TRUE" if len(match) > 1: mappa[ "msg"] = "Warning: more than one guest matches the data you entered. Please insert more data." mappa["error"] = "TRUE" mappa["guests"] = match[0] mappa["checkin"] = int(checkin) mappa["checkout"] = int(checkout) print mappa template = env.get_template("booking_confirm.html") return template.render(mappa)
def confirm(checkin, checkout): """ confirm() This page shows a sum-up of all the information inserted by the receptionist. Guest's data goes through some preprocessing before being shown: it's processed by matching_guest() in order to find if the guest has already been registered in the database. Four cases can be distinguished: - matching_guest() found only one perfectly matching row in the database. In this case the infos shown are the ones found in the database. - matching_guest() found no perfectly matching rows in the database. - matching_guest() found one partial match. in this case the receptionist is asked to modify the database in order to update guest's data, instead than inserting a new entry. - matching_guest() found more than one partial match. In this case The receptionist is asked to choose the guest between the partial matching ones and modify it, or to insert a completely new entry. - matching_guest() found no matching rows. In this case the data shown are the one the receptionist entered before. matching_guest() permits to distinguish between "completely matching" and "partially matching". - Perfectly matching: all the fields matches, notes excluded. - Partially matching: name, surname, passport matches. """ if not session.get('logged_in'): abort(401) mappa = {"ckin": dataINT_to_datatime(int(checkin)), "ckout": dataINT_to_datatime(int(checkout))} sel_rooms=[] for room in free_rooms(checkin, checkout): if request.args.get(str(room[0])) == "on": sel_rooms.append(room) mappa["rooms"] = sel_rooms #Temo calcoli il prezzo sbagliato!! ************************************* <------------------ price = 0 for room in sel_rooms: price = price + price_from_room_id(room[0])*(int(checkout)-int(checkin)) mappa["price"] = price guest = [] keys = [] match = [] mappa["error"] = "FALSE" for item in ["name", "surname", "email", "passport", "phone", "address", "notes"]: if request.args[item] != "": guest.append(request.args[item]) keys.append(item) match = matching_guest(keys, guest) if not match: for item in ["name", "surname", "passport"]: if request.args[item] != "": guest.append(request.args[item]) keys.append(item) match = matching_guest(keys, guest) if not match: g = [] g.append(n_items("guests", "", "") + 1) #The new ID for item in ["name", "surname", "email", "passport", "phone", "address", "notes"]: g.append(request.args[item]) if not request.args[item]: g.append("") if g[1] == "" or g[2] == "" or g[4] == "": mappa["msg"] = "You must insert name, surname, and passport No of the guest." mappa["error"] = "TRUE" match.append(g) mappa["new_guest"] = "TRUE" if len(match)>1: mappa["msg"] = "Warning: more than one guest matches the data you entered. Please insert more data." mappa["error"] = "TRUE" mappa["guests"] = match[0] mappa["checkin"] = int(checkin) mappa["checkout"] = int(checkout) print mappa template = env.get_template("booking_confirm.html") return template.render(mappa)