Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from cs50 import SQL
- import os
- import re
- from flask import Flask, flash, redirect, render_template, request, session, url_for
- from flask_session import Session
- import feedparser
- import urllib.parse
- from flask_jsglue import JSGlue
- from passlib.apps import custom_app_context as pwd_context
- from tempfile import mkdtemp
- # configure application
- app = Flask(__name__)
- JSGlue(app)
- # ensure responses aren't cached
- if app.config["DEBUG"]:
- @app.after_request
- def after_request(response):
- response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
- response.headers["Expires"] = 0
- response.headers["Pragma"] = "no-cache"
- return response
- # configure session to use filesystem (instead of signed cookies)
- app.config["SESSION_FILE_DIR"] = mkdtemp()
- app.config["SESSION_PERMANENT"] = False
- app.config["SESSION_TYPE"] = "filesystem"
- Session(app)
- # configure CS50 Library to use SQLite database
- db = SQL("sqlite:///hotel.db")
- @app.route("/")
- def index():
- """welcome page."""
- return render_template("index.html")
- @app.route("/signup", methods=["GET", "POST"])
- def signup():
- """User register by creating an account."""
- # forget any user_id
- session.clear()
- # if user reached route via POST (as by submitting a form via POST)
- if request.method == "POST":
- # #make sure that the username choosen doesn't exist already, otherwise create the new user
- # result = db.execute("INSERT INTO users (username, hash) VALUES (:username, :hash)", username=request.form.get("username"), hash=pwd_context.hash(request.form.get("password")))
- # if not result:
- # return apology("username already exist")
- #create a new line in database with all the infos for the new user/ type will be automatically client
- db.execute("INSERT INTO users (name, last_name, email, password, phone)\
- VALUES (:name, :last_name, :email, :password, :phone)",\
- name=request.form.get("name"), last_name=request.form.get("lastname"), email=request.form.get("email"), \
- password=request.form.get("password"), phone=request.form.get("phone"))
- #get the user_id to use it in session
- rows = db.execute("SELECT * FROM users WHERE email = :email", email=request.form.get("email"))
- # remember which user has logged in
- session["user_id"] = rows[0]["user_id"]
- session["type"] = rows[0]["type"]
- # redirect user to home page
- return redirect(url_for("index"))
- # else if user reached route via GET (as by clicking a link or via redirect)
- else:
- return render_template("signup.html")
- @app.route("/login", methods=["GET", "POST"])
- def login():
- """Log user in."""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # make sure that the username which is email and the password are correct
- # rows = db.execute("SELECT * FROM users WHERE email = :email", email=email=request.form.get("email"))
- # # ensure username exists and password is correc
- # if len(rows) != 1 or not pwd_context.verify(request.form.get("password"), rows[0]["hash"]):
- # return alert("invalid username and/or password")
- # # remember which user has logged in
- # session["user_id"] = rows[0]["user_id"]
- # session["type"] = rows[0]["type"]
- # #if user already done a research, make sure to send right away the confirmation for him not to restart the search.
- # #if button confirmation is clicked
- # #return to reservation part where the confirmation template will be send to client
- # # redirect user to home page
- # return redirect(url_for("index"))
- # # else if user reached route via GET (as by clicking a link or via redirect)
- # else:
- # return render_template("login.html")
- @app.route("/logout")
- def logout():
- """Log user out."""
- # # forget any user_id
- # session.clear()
- # # redirect user to the home page
- # return redirect(url_for("index"))
- @app.route("/reservation", methods=["GET", "POST"])
- def reservation():
- """Client is reserving a room by dates."""
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # #get the date to check in database which room match for booking
- # date_start = request.form.get["date_start"]
- # date_end = request.form.get["date_end"]
- # # check the room that are status available when reservation has no date_start adn no date_end
- # result = db.execute("SELECT * FROM reservations WHERE date_start = :date_start AND date_end = :date_end innerjoin * FROM room, status='available')
- # if not date_start < result["date_start"] || date_end > result["date_end"]
- # return alert("sorry no room is avaialbe for choosen dates")
- # #get the price of each room available
- # result = db.execute("SELECT * FROM rooms WHERE price = :price")
- # #calculate for each room the total price depending of the room and the nights
- # nigths = date_end - date_start
- # total price = result["price"] * nigths
- # # return to client the infos about each room with status available
- # return render_template(url_for("options"), #room with statut available with bottom to click reserve for each room)
- # # #client have a button to make the reservation
- # # if session["user_id"]
- # # #if user is not log, message to make him log or register
- # # else redirect(url'log in')
- # #add a line in reservation to the database
- # rows = db.execute("INSERT INTO reservation (date_start, date_end, room_id, user_id, total_price, number_person, status) \
- # VALUES (:date_start, :date_end, :room_id, :total_price, :user_id, status)",\
- # user_id=session["user_id"], date_start=request.form.get("date_start"), date_end=request.form.get("date_end"),\
- # room_id=room_id, total_price=total_price(room_id))
- # #show the reservation number confirmation with the option to cancel / do i want to send an email confirmation ?
- # #do i want to propose here the bottom to cancel
- # return render_template("confirmation.html", reservation_id=reservation_id, date start=date_start, date end= date_end)
- # #
- # # remember which user has logged in
- # session["user_id"] = rows[0]["id"]
- # # redirect user to home page
- # return redirect(url_for("index"))
- # # else if user reached route via GET (as by clicking a link or via redirect)
- # else:
- # return render_template("reservation.html")
- @app.route("/reserved", methods=["GET", "POST"])
- def reserved():
- """client access all his reservation done with option to cancel."""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # get only the reservation done with all status for only one client
- # result = db.execute("SELECT * FROM reservations WHERE user_id= :user_id", user_id=session["user_id"])
- # #show to client all the reservation done in the past and the reservation
- # return render_template("reserved.html", reservation=reservations)
- # # # else if user reached route via GET (as by clicking a link or via redirect)
- # # else:
- # # return render_template("login.html")
- @app.route("/history", methods=["GET", "POST"])
- def history():
- """admin access history of all reservation done with all status for all clients."""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # query database to get all the reservation done
- # result = db.execute("SELECT * FROM reservations WHERE reservation_id =:reservation_id", reservation_id=reservation_id)
- # #return the info to user
- # return render_template("history.html", histories=history)
- # # else if user reached route via GET (as by clicking a link or via redirect)
- # else:
- # return render_template("history.html")
- @app.route("/booking", methods=["GET", "POST"])
- def booking():
- """list of all rooms reserved with option to confirm or cancel"""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # query database for checkin availability of the room
- # result = db.execute("SELECT * FROM reservation WHERE status= :status", status='reserved')
- # return render_template("booking.html", reservation=reservations, user=users)
- # # # else if user reached route via GET (as by clicking a link or via redirect)
- # # else:
- # # return render_template("login.html")
- @app.route("/availability", methods=["GET", "POST"])
- def availability():
- """all the rooms that are availabe"""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # query database for checkin availability of the room
- # result = db.execute("SELECT * FROM rooms WHERE status= :status", status='available')
- # return render_template("availability.html", room=rooms)
- # # # else if user reached route via GET (as by clicking a link or via redirect)
- # # else:
- # # return render_template("login.html")
- @app.route("/occupancy", methods=["GET", "POST"])
- def occupancy():
- """all the rooms that are used"""
- # # forget any user_id
- # session.clear()
- # # if user reached route via POST (as by submitting a form via POST)
- # if request.method == "POST":
- # # query database for checkin availability of the room
- # result = db.execute("SELECT * FROM rooms WHERE status= :status", status='occupied')
- # # # else if user reached route via GET (as by clicking a link or via redirect)
- # # else:
- # # return render_template("login.html")
- # @app.route("/confirm")
- # def confirm():
- # """Admin confirm reservation when client is arrived at hotel."""
- # #get the reservation with the status reserverd
- # #buttom that switch status or reservation to reserved to confirmed
- # db.execute("UPDATE reservations SET status :status WHERE reservation_id = :reservation_id", status='confirmed')
- # # #change the room status from reserved to occupied
- # # db.execute("UPDATE rooms SET status :status WHERE room_id = :room_id", status='occupied', room_id=room_id)
- # #create a new line to history db
- # #rows = db.execute("INSERT INTO history (id, symbol, shares, price, cost, transaction_type) VALUES (:id, :symbol,:shares, :price, :cost, :transaction_type)",\
- # # id=session["user_id"], shares=request.form.get("number_shares"), symbol=result["symbol"], price=usd(result["price"]), cost=usd(update_cash),\
- # # transaction_type='Sell')
- # @app.route("/cancel")
- # def cancel():
- # """reservation is cancelled."""
- # # #buttom that switch reservation status from reserved to available
- # # db.execute("UPDATE reservations SET status :status WHERE reservation_id = :reservation_id", status='cancel', room_id=room_id)
- # # #change the room status from reserved to cancel
- # # db.execute("UPDATE rooms SET status :status WHERE room_id = :room_id", status='available', room_id=room_id)
- # #add the reservation to the database
- # # rows = db.execute("INSERT INTO reservation (id, date start, date end, room id, total price, reservation time, number person, status) \
- # # VALUES (:id, :date_start, :date_end, :total_price, :room_id, :user_id, status)",\
- # # id=reservation_id, user_id=session["user_id"], date_start=request.form.get("date_start"), date_end=request.form.get("date_end")
- # # , total_price=total_price(room_id), Sell')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement