Skip to content

Commit

Permalink
Take web_flask from AirBnB V2
Browse files Browse the repository at this point in the history
  • Loading branch information
jzamora5 committed May 15, 2020
1 parent a1545f8 commit 5f23a59
Show file tree
Hide file tree
Showing 49 changed files with 1,423 additions and 0 deletions.
14 changes: 14 additions & 0 deletions web_flask/0-hello_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from flask import Flask
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'

if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
20 changes: 20 additions & 0 deletions web_flask/1-hbnb_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3
""" Starts a Flash Web Application HBNB"""
from flask import Flask
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'

if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
40 changes: 40 additions & 0 deletions web_flask/10-hbnb_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from models.city import City
from models.amenity import Amenity
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True


@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()


@app.route('/hbnb_filters', strict_slashes=False)
def hbnb_filter():
""" HBNB filters """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
st_ct = []

for state in states:
st_ct.append([state, sorted(state.cities, key=lambda k: k.name)])

amenities = storage.all(Amenity).values()
amenities = sorted(amenities, key=lambda k: k.name)

return render_template('10-hbnb_filters.html',
states=st_ct,
amenities=amenities)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
248 changes: 248 additions & 0 deletions web_flask/100-dump.sql

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions web_flask/100-hbnb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from models.city import City
from models.amenity import Amenity
from models.place import Place
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True


@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" HBNB is alive! """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
st_ct = []

for state in states:
st_ct.append([state, sorted(state.cities, key=lambda k: k.name)])

amenities = storage.all(Amenity).values()
amenities = sorted(amenities, key=lambda k: k.name)

places = storage.all(Place).values()
places = sorted(places, key=lambda k: k.name)

return render_template('100-hbnb.html',
states=st_ct,
amenities=amenities,
places=places)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
40 changes: 40 additions & 0 deletions web_flask/100-hbnb.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from models.city import City
from models.amenity import Amenity
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True


@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()


@app.route('/hbnb', strict_slashes=False)
def states_state():
""" HBNB is alive! """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
st_ct = []

for state in states:
st_ct.append([state, sorted(state.cities, key=lambda k: k.name)])

amenities = storage.all(Amenity).values()
amenities = sorted(amenities, key=lambda k: k.name)

return render_template('100-hbnb.html',
states=st_ct,
amenities=amenities)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
26 changes: 26 additions & 0 deletions web_flask/2-c_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python3
""" Starts a Flash Web Application C is FUN"""
from flask import Flask
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'


@app.route('/c/<text>', strict_slashes=False)
def c_is_fun(text):
""" Prints a Message when /c is called """
return "C " + text.replace('_', ' ')

if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
33 changes: 33 additions & 0 deletions web_flask/3-python_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3
""" Starts a Flash Web Application Python is Cool"""
from flask import Flask
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'


@app.route('/c/<text>', strict_slashes=False)
def c_is_fun(text):
""" Prints a Message when /c is called """
return "C " + text.replace('_', ' ')


@app.route('/python', strict_slashes=False)
@app.route('/python/<text>', strict_slashes=False)
def python_is_cool(text='is_cool'):
""" Prints a Message when /python is called """
return "Python " + text.replace('_', ' ')

if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
39 changes: 39 additions & 0 deletions web_flask/4-number_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
""" Starts a Flash Web Application Python is Cool"""
from flask import Flask
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'


@app.route('/c/<text>', strict_slashes=False)
def c_is_fun(text):
""" Prints a Message when /c is called """
return "C " + text.replace('_', ' ')


@app.route('/python', strict_slashes=False)
@app.route('/python/<text>', strict_slashes=False)
def python_is_cool(text='is_cool'):
""" Prints a Message when /python is called """
return "Python " + text.replace('_', ' ')


@app.route('/number/<int:n>', strict_slashes=False)
def is_n_number(n):
""" Prints a Message when /number is called only if n is an int"""
return "{:d} is a number".format(n)

if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
46 changes: 46 additions & 0 deletions web_flask/5-number_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from flask import Flask, render_template
app = Flask(__name__)


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'


@app.route('/c/<text>', strict_slashes=False)
def c_is_fun(text):
""" Prints a Message when /c is called """
return "C " + text.replace('_', ' ')


@app.route('/python', strict_slashes=False)
@app.route('/python/<text>', strict_slashes=False)
def python_is_cool(text='is_cool'):
""" Prints a Message when /python is called """
return "Python " + text.replace('_', ' ')


@app.route('/number/<int:n>', strict_slashes=False)
def is_n_number(n):
""" Prints a Message when /number is called only if n is an int"""
return "{:d} is a number".format(n)


@app.route('/number_template/<int:n>', strict_slashes=False)
def number_template(n):
""" display a HTML page only if n is an integer """
return render_template('5-number.html', value=n)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
54 changes: 54 additions & 0 deletions web_flask/6-number_odd_or_even.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from flask import Flask, render_template
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True


@app.route('/', strict_slashes=False)
def hello_hbnb():
""" Prints a Message when / is called """
return 'Hello HBNB!'


@app.route('/hbnb', strict_slashes=False)
def hbnb():
""" Prints a Message when /hbnb is called """
return 'HBNB'


@app.route('/c/<text>', strict_slashes=False)
def c_is_fun(text):
""" Prints a Message when /c is called """
return "C " + text.replace('_', ' ')


@app.route('/python', strict_slashes=False)
@app.route('/python/<text>', strict_slashes=False)
def python_is_cool(text='is_cool'):
""" Prints a Message when /python is called """
return "Python " + text.replace('_', ' ')


@app.route('/number/<int:n>', strict_slashes=False)
def is_n_number(n):
""" Prints a Message when /number is called only if n is an int"""
return "{:d} is a number".format(n)


@app.route('/number_template/<int:n>', strict_slashes=False)
def number_template(n):
""" display a HTML page only if n is an integer """
return render_template('5-number.html', value=n)


@app.route('/number_odd_or_even/<int:n>', strict_slashes=False)
def odd_or_even(n):
""" display a HTML page only if n is an integer """
return render_template('6-number_odd_or_even.html', value=n)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
27 changes: 27 additions & 0 deletions web_flask/7-states_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True


@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()


@app.route('/states_list', strict_slashes=False)
def states_list():
""" displays a HTML page with a list of states """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
return render_template('7-states_list.html', states=states)


if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)
Loading

0 comments on commit 5f23a59

Please sign in to comment.