1- from datetime import datetime
21import os
2+ from datetime import datetime
33
4- from flask import Flask , render_template , request , redirect , url_for , send_from_directory
5- from flask_sqlalchemy import SQLAlchemy
4+ from flask import Flask , redirect , render_template , request , send_from_directory , url_for
65from flask_migrate import Migrate
6+ from flask_sqlalchemy import SQLAlchemy
77from flask_wtf .csrf import CSRFProtect
88
99
1010app = Flask (__name__ , static_folder = 'static' )
1111csrf = CSRFProtect (app )
1212
1313# WEBSITE_HOSTNAME exists only in production environment
14- if not 'WEBSITE_HOSTNAME' in os .environ :
15- # local development, where we'll use environment variables
16- print ("Loading config.development and environment variables from .env file." )
17- app .config .from_object ('azureproject.development' )
14+ if 'WEBSITE_HOSTNAME' not in os .environ :
15+ # local development, where we'll use environment variables
16+ print ("Loading config.development and environment variables from .env file." )
17+ app .config .from_object ('azureproject.development' )
1818else :
19- # production
20- print ("Loading config.production." )
21- app .config .from_object ('azureproject.production' )
19+ # production
20+ print ("Loading config.production." )
21+ app .config .from_object ('azureproject.production' )
2222
2323app .config .update (
2424 SQLALCHEMY_DATABASE_URI = app .config .get ('DATABASE_URI' ),
3737@app .route ('/' , methods = ['GET' ])
3838def index ():
3939 print ('Request for index page received' )
40- restaurants = Restaurant .query .all ()
40+ restaurants = Restaurant .query .all ()
4141 return render_template ('index.html' , restaurants = restaurants )
4242
4343@app .route ('/<int:id>' , methods = ['GET' ])
4444def details (id ):
4545 restaurant = Restaurant .query .where (Restaurant .id == id ).first ()
46- reviews = Review .query .where (Review .restaurant == id )
46+ reviews = Review .query .where (Review .restaurant == id )
4747 return render_template ('details.html' , restaurant = restaurant , reviews = reviews )
4848
4949@app .route ('/create' , methods = ['GET' ])
@@ -94,21 +94,21 @@ def add_review(id):
9494 review .review_text = review_text
9595 db .session .add (review )
9696 db .session .commit ()
97-
98- return redirect (url_for ('details' , id = id ))
97+
98+ return redirect (url_for ('details' , id = id ))
9999
100100@app .context_processor
101101def utility_processor ():
102102 def star_rating (id ):
103- reviews = Review .query .where (Review .restaurant == id )
103+ reviews = Review .query .where (Review .restaurant == id )
104104
105105 ratings = []
106- review_count = 0 ;
106+ review_count = 0
107107 for review in reviews :
108108 ratings += [review .rating ]
109109 review_count += 1
110110
111- avg_rating = sum (ratings )/ len (ratings ) if ratings else 0
111+ avg_rating = sum (ratings ) / len (ratings ) if ratings else 0
112112 stars_percent = round ((avg_rating / 5.0 ) * 100 ) if review_count > 0 else 0
113113 return {'avg_rating' : avg_rating , 'review_count' : review_count , 'stars_percent' : stars_percent }
114114
@@ -120,4 +120,4 @@ def favicon():
120120 'favicon.ico' , mimetype = 'image/vnd.microsoft.icon' )
121121
122122if __name__ == '__main__' :
123- app .run ()
123+ app .run ()
0 commit comments