Foundations > Higher-level programming > AirBnB clone
Guillaume Salva
08-31-2020 to 09-03-2020
Third of three projects building the second iteration of a website cloning the basic features of the airbnb.com
main page, circa 2014-2017.
Using the Python library Flask along with Jinja templates to create a web framework and application to dynamically display the contents of our storage engines.
- Interpreter conditions:
- Ubuntu 14.04 LTS
- python3 (version 3.4.3)
- First line of executable scripts will be
#!/usr/bin/python3
- Compliance with linter:
pep8
(version 1.7.*) (now known aspycodestyle
)
- Docstrings are expected to follow the Google style guide:
- Per module (
python3 -c 'print(__import__("my_module").__doc__)'
) - Per class (
python3 -c 'print(__import__("my_module").MyClass.__doc__)'
) - Per function
- both inside a class (
python3 -c 'print(__import__("my_module").MyClass.my_function.__doc__)'
) - and outside a class (
python3 -c 'print(__import__("my_module").my_function.__doc__)'
)
- both inside a class (
- Per module (
- Test scripts will typically not be in same directory as the task solutions, use
export PYTHONPATH='.'
before running test scripts from project directory to allow includes - Unit tests will be required on some projects:
- using the unittest module
- located in a
tests/
folder, with a file structure mimicing that of your project, but with atest_
prefix added to all file/directory names - tests should be capable of being run with
python3 -m unittest discover tests
, or individually per file withpython3 -m unittest <test file>
- Your code should be W3C compliant and validate with W3C-Validator
- All your CSS files should be in
styles
folder - All your images should be in
images
folder - You are not allowed to use
!important
andid
(#...
in the CSS file) - You are not allowed to use tags
img
,embed
andiframe
- You are not allowed to use Javascript
- Example screenshots taken on Chrome 56
- No cross browsers
- You have to follow all requirements but some
margin
/padding
are missing - you should try to fit as much as you can to screenshots
$ pip3 install Flask
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: display “Hello HBNB!”
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/0-hello_route.py
web_flask/__init__.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: displayHello HBNB!
/hbnb
: displayHBNB
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/1-hbnb_route.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: displayHello HBNB!
/hbnb
: displayHBNB
/c/<text>
: displayC
followed by the value of the text variable (replace underscore_
symbols with a space )
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/2-c_route.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: displayHello HBNB!
/hbnb
: displayHBNB
/c/<text>
: displayC
, followed by the value of the text variable (replace underscore_
symbols with a space )/python/(<text>)
: displayPython
, followed by the value of the text variable (replace underscore_
symbols with a space )- The default value of text is
is cool
- The default value of text is
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/3-python_route.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: displayHello HBNB!
/hbnb
: displayHBNB
/c/<text>
: displayC
, followed by the value of the text variable (replace underscore_
symbols with a space )/python/(<text>)
: displayPython
, followed by the value of the text variable (replace underscore_
symbols with a space )- The default value of text is
is cool
- The default value of text is
/number/<n>
: displayn is a number
only ifn
is an integer
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/4-number_route.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: display “Hello HBNB!`/hbnb
: displayHBNB
/c/<text>
: displayC
, followed by the value of the text variable (replace underscore_
symbols with a space )/python/(<text>)
: displayPython
, followed by the value of the text variable (replace underscore_
symbols with a space )- The default value of text is
is cool
- The default value of text is
/number/<n>
: displayn is a number
only ifn
is an integer/number_template/<n>
: display a HTML page only ifn
is an integer:H1
tag:Number: n
inside the tag BODY
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/5-number_template.py
web_flask/templates/5-number.html
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- Routes:
/
: displayHello HBNB!
/hbnb
: displayHBNB
/c/<text>
: displayC
, followed by the value of the text variable (replace underscore_
symbols with a space )/python/(<text>)
: displayPython
, followed by the value of the text variable (replace underscore_
symbols with `a space )- The default value of text is
is cool
- The default value of text is
/number/<n>
: displayn is a number
only ifn
is an integer/number_template/<n>
: display a HTML page only ifn
is an integer:H1
tag:Number: n
inside the tagBODY
- `/number_odd_or_even/: display a HTML page only if n is an integer:
H1
tag:Number: n is even|odd
inside the tagBODY
- You must use the option
strict_slashes=False
in your route definition
File(s): web_flask/6-number_odd_or_even.py
web_flask/templates/6-number_odd_or_even.html
Before using Flask to display our HBNB data, you will need to update some part of our engine:
Update FileStorage
: (models/engine/file_storage.py
)
- Add a public method
def close(self):
: callreload()
method for deserializing the JSON file to objects
Update DBStorage
: (models/engine/db_storage.py
)
- Add a public method
def close(self):
: callremove()
method on the private session attribute (self.__session
) tips orclose()
on the classSession
tips
Update State
: (models/state.py
) - If it’s not already present
- If your storage engine is not
DBStorage
, add a public getter methodcities
to return the list ofCity
objects from storage linked to the currentState
File(s): models/engine/file_storage.py
models/engine/db_storage.py
models/state.py
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- You must use
storage
for fetching data from the storage engine (FileStorage
orDBStorage
) =>from models import storage and storage.all(...)
- After each request you must remove the current SQLAlchemy Session:
- Declare a method to handle
@app.teardown_appcontext
- Call in this method
storage.close()
- Declare a method to handle
- Routes:
/states_list
: display a HTML page: (inside the tagBODY
)H1
tag:States
UL
tag: with the list of allState
objects present inDBStorage
sorted by name (A->Z)LI
tag: description of oneState
:<state.id>: <B><state.name></B>
- Import this
7-states_list.sql
to have some data - You must use the option
strict_slashes=False
in your route definition
IMPORTANT
- Make sure you have a running and valid
setup_mysql_dev.sql
in yourAirBnB_clone_v2
repository (task) - Make sure all tables are created when you run
echo "quit" | HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db ./console.py
File(s): web_flask/7-states_list.py
web_flask/templates/7-states_list.html
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- You must use
storage
for fetching data from the storage engine (FileStorage
orDBStorage
) =>from models import storage
andstorage.all(...)
- To load all cities of a
State
:- If your storage engine is
DBStorage
, you must usecities
relationship - Otherwise, use the public getter method
cities
- If your storage engine is
- After each request you must remove the current SQLAlchemy Session:
- Declare a method to handle
@app.teardown_appcontext
- Call in this method
storage.close()
- Declare a method to handle
- Routes:
/cities_by_states
: display a HTML page: (inside the tagBODY
)H1
tag:States
UL
tag: with the list of allState
objects present inDBStorage
sorted by name (A->Z)LI
tag: description of oneState
:<state.id>: <B><state.name></B>
+UL
tag: with the list ofCity
objects linked to theState
sorted byname
(A->Z)LI
tag: description of oneCity
: <city.id>: <city.name>`
- Import this
7-states_list.sql
to have some data - You must use the option
strict_slashes=False
in your route definition
IMPORTANT
- Make sure you have a running and valid
setup_mysql_dev.sql
in yourAirBnB_clone_v2
repository (task) - Make sure all tables are created when you run
echo "quit" | HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db ./console.py
File(s): web_flask/8-cities_by_states.py
web_flask/templates/8-cities_by_states.html
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- You must use
storage
for fetching data from the storage engine (FileStorage
orDBStorage
) =>from models import storage
andstorage.all(...)
- To load all cities of a
State
:- If your storage engine is
DBStorage
, you must usecities
relationship - Otherwise, use the public getter method
cities
- If your storage engine is
- After each request you must remove the current SQLAlchemy Session:
- Declare a method to handle
@app.teardown_appcontext
- Call in this method
storage.close()
- Declare a method to handle
- Routes:
/states
: display a HTML page: (inside the tagBODY
)H1
tag:States
UL
tag: with the list of allState
objects present inDBStorage
sorted by name (A->Z)LI
tag: description of oneState
:<state.id>: <B><state.name></B>
/states/<id>
: display a HTML page: (inside the tagBODY
)- If a
State
object is found with thisid
:H1
tag:State:
H3
tag:Cities:
UL
tag: with the list ofCity
objects linked to theState
sorted byname
(A->Z)LI
tag: description of oneCity
:<city.id>: <B><city.name></B>
- Otherwise:
H1
tag:Not found!
- If a
- You must use the option
strict_slashes=False
in your route definition - Import this
7-states_list.sql
to have some data
IMPORTANT
- Make sure you have a running and valid
setup_mysql_dev.sql
in yourAirBnB_clone_v2
repository (task) - Make sure all tables are created when you run
echo "quit" | HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db ./console.py
File(s): web_flask/9-states.py
web_flask/templates/9-states.html
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- You must use
storage
for fetching data from the storage engine (FileStorage
orDBStorage
) =>from models import storage
andstorage.all(...)
- To load all cities of a
State
:- If your storage engine is
DBStorage
, you must usecities
relationship - Otherwise, use the public getter method
cities
- If your storage engine is
- After each request you must remove the current SQLAlchemy Session:
- Declare a method to handle
@app.teardown_appcontext
- Call in this method
storage.close()
- Declare a method to handle
- Routes:
/hbnb_filters
: display a HTML page like6-index.html
, which was done during the project 0x01. AirBnB clone - Web static- Copy files
3-footer.css
,3-header.css
,4-common.css
and6-filters.css
fromweb_static/styles/
to the folderweb_flask/static/styles
- Copy files
icon.png
andlogo.png
fromweb_static/images/
to the folderweb_flask/static/images
- Update
.popover
class in6-filters.css
to allow scrolling in the popover and a max height of 300 pixels. - Use
6-index.html
content as source code for the template10-hbnb_filters.html
:- Replace the content of the
H4
tag under each filter title (H3
States andH3
Amenities) by
- Replace the content of the
State
,City
andAmenity
objects must be loaded fromDBStorage
and sorted by name (A->Z)
- Copy files
- You must use the option
strict_slashes=False
in your route definition - Import this
10-hbnb_filters.sql
to have some data
IMPORTANT
- Make sure you have a running and valid
setup_mysql_dev.sql
in yourAirBnB_clone_v2
repository (task) - Make sure all tables are created when you run
echo "quit" | HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db ./console.py
File(s): web_flask/10-hbnb_filters.py
web_flask/templates/10-hbnb_filters.html
web_flask/static/
Write a script that starts a Flask web application:
- Your web application must be listening on
0.0.0.0
, port5000
- You must use
storage
for fetching data from the storage engine (FileStorage
orDBStorage
) =>from models import storage
andstorage.all(...)
- To load all cities of a
State
:- If your storage engine is
DBStorage
, you must usecities
relationship - Otherwise, use the public getter method
cities
- If your storage engine is
- After each request you must remove the current SQLAlchemy Session:
- Declare a method to handle
@app.teardown_appcontext
- Call in this method
storage.close()
- Declare a method to handle
- Routes:
/hbnb
: display a HTML page like8-index.html
, done during the 0x01. AirBnB clone - Web static project- Copy files
3-footer.css
,3-header.css
,4-common.css
,6-filters.css
and8-places.css
fromweb_static/styles/
to the folderweb_flask/static/styles
- Copy all files from
web_static/images/
to the folderweb_flask/static/images
- Update
.popover
class in6-filters.css
to enable scrolling in the popover and set max height to 300 pixels. - Update
8-places.css
to always have the price by night on the top right of each place element, and the name correctly aligned and visible - Use
8-index.html
content as source code for the template100-hbnb.html
:- Replace the content of the
H4
tag under each filter title (H3
States andH3
Amenities) by
- Make sure all HTML tags from objects are correctly used (example:
<BR />
must generate a new line)
- Replace the content of the
State
,City
,Amenity
andPlace
objects must be loaded from DBStorage and sorted by name (A->Z)
- Copy files
- You must use the option
strict_slashes=False
in your route definition - Import this
100-hbnb.sql
to have some data
IMPORTANT
- Make sure you have a running and valid
setup_mysql_dev.sql
in your AirBnB_clone_v2 repository (task) - Make sure all tables are created when you run
echo "quit" | HBNB_MYSQL_USER=hbnb_dev HBNB_MYSQL_PWD=hbnb_dev_pwd HBNB_MYSQL_HOST=localhost HBNB_MYSQL_DB=hbnb_dev_db HBNB_TYPE_STORAGE=db ./console.py
File(s): web_flask/100-hbnb.py
web_flask/templates/100-hbnb.html
web_flask/static/
- Samuel Pomeroy - allelomorph