-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-hbnb.py
executable file
·49 lines (38 loc) · 1.3 KB
/
3-hbnb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
""" Starts a Flash Web Application """
import uuid
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('/3-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)
cache_id = uuid.uuid4()
return render_template('3-hbnb.html',
states=st_ct,
amenities=amenities,
places=places,
cache_id=cache_id)
if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)