/delete',
+ methods=['GET', 'POST']
+)
+@login_required
+def delete_menu_item(restaurant_id, menu_id):
+ try:
+ restaurant = session.query(Restaurant).filter_by(
+ id=restaurant_id
+ ).one()
+ except:
+ return "No such restaurant"
+ try:
+ item_to_delete = session.query(MenuItem).filter_by(
+ id=menu_id
+ ).one()
+ except:
+ return "No such item"
if login_session['user_id'] != restaurant.user_id:
- return ""
+ return ""
if request.method == 'POST':
- session.delete(itemToDelete)
+ session.delete(item_to_delete)
session.commit()
flash('Menu Item Successfully Deleted')
- return redirect(url_for('showMenu', restaurant_id=restaurant_id))
+ return redirect(url_for('show_menu', restaurant_id=restaurant_id))
else:
- return render_template('deleteMenuItem.html', item=itemToDelete)
+ return render_template('deleteMenuItem.html', item=item_to_delete)
# Disconnect based on provider
@app.route('/disconnect')
def disconnect():
if 'provider' in login_session:
- if login_session['provider'] == 'google':
- gdisconnect()
- del login_session['gplus_id']
- del login_session['credentials']
- if login_session['provider'] == 'facebook':
- fbdisconnect()
- del login_session['facebook_id']
- del login_session['username']
- del login_session['email']
- del login_session['picture']
- del login_session['user_id']
- del login_session['provider']
+ remove_session()
flash("You have successfully been logged out.")
- return redirect(url_for('showRestaurants'))
+ return redirect(url_for('show_restaurants'))
else:
flash("You were not logged in")
- return redirect(url_for('showRestaurants'))
+ return redirect(url_for('show_restaurants'))
if __name__ == '__main__':
- app.secret_key = 'super_secret_key'
- app.debug = True
- app.run(host='0.0.0.0', port=5000)
+ app.secret_key = main_app.get('secret_key', 'super_secret_key')
+ app.debug = main_app.get('debug', True)
+ app.config['SESSION_TYPE'] = main_app.get('session_type', 'filesystem')
+ app.run(
+ host=main_app.get('host', '0.0.0.0'),
+ port=main_app.get('port', 5000)
+ )
diff --git a/Lesson4/step2/requirements.txt b/Lesson4/step2/requirements.txt
new file mode 100644
index 0000000..3bf07bd
--- /dev/null
+++ b/Lesson4/step2/requirements.txt
@@ -0,0 +1,19 @@
+certifi==2017.7.27.1
+chardet==3.0.4
+click==6.7
+Flask==0.12.2
+httplib2==0.10.3
+idna==2.6
+itsdangerous==0.24
+Jinja2==2.9.6
+MarkupSafe==1.0
+oauth2client==4.1.2
+pyasn1==0.3.2
+pyasn1-modules==0.0.11
+python-dotenv==0.6.5
+requests==2.18.4
+rsa==3.4.2
+six==1.10.0
+SQLAlchemy==1.1.13
+urllib3==1.22
+Werkzeug==0.12.2
diff --git a/Lesson4/step2/restaurantmenu.db b/Lesson4/step2/restaurantmenu.db
deleted file mode 100644
index e69de29..0000000
diff --git a/Lesson4/step2/restaurantmenuwithusers.db b/Lesson4/step2/restaurantmenuwithusers.db
index 7bfdd06..0417312 100644
Binary files a/Lesson4/step2/restaurantmenuwithusers.db and b/Lesson4/step2/restaurantmenuwithusers.db differ
diff --git a/Lesson4/step2/static/styles.css b/Lesson4/step2/static/styles.css
index df225bb..72bab5a 100644
--- a/Lesson4/step2/static/styles.css
+++ b/Lesson4/step2/static/styles.css
@@ -1,163 +1,193 @@
* {
- font-family: "Helvetica Neue Bold", Roboto, Helvetica, Arial, sans-serif;
- font-weight: 700;
+ font-family: "Helvetica Neue Bold", Roboto, Helvetica, Arial, sans-serif;
+ font-weight: 700;
}
h1 {
- font-family: "Helvetica Neue Light", Roboto, Helvetica, Arial, sans-serif;
- font-size: 50px;
- color: #51453B;
- line-height: 60px;
- font-weight: 300;
+ font-family: "Helvetica Neue Light", Roboto, Helvetica, Arial, sans-serif;
+ font-size: 50px;
+ color: #51453B;
+ line-height: 60px;
+ font-weight: 300;
}
h2 {
- font-size: 24px;
- color: #42C3C9;
- line-height: 29px;
+ font-size: 24px;
+ color: #42C3C9;
+ line-height: 29px;
}
h3 {
- font-size: 18px;
- color: #4A4A4A;
- line-height: 23px;
-}
- p {
- font-family: "Helvetica Neue", Roboto, Helvetica, Arial, sans-serif;
- font-size: 16px;
- color: #7B7573;
- line-height: 24px;
- font-weight: 400;
- }
-
- strong {
- font-size: 16px;
- color: #7B7573;
- line-height: 24px;
- }
-
- a {
- font-size: 14px;
- color: #0093B9;
- line-height: 17px;
- }
+ font-size: 18px;
+ color: #4A4A4A;
+ line-height: 23px;
+}
+
+p {
+ font-family: "Helvetica Neue", Roboto, Helvetica, Arial, sans-serif;
+ font-size: 16px;
+ color: #7B7573;
+ line-height: 24px;
+ font-weight: 400;
+}
+
+strong {
+ font-size: 16px;
+ color: #7B7573;
+ line-height: 24px;
+}
+
+a {
+ font-size: 14px;
+ color: #0093B9;
+ line-height: 17px;
+}
+
.padding-top {
- padding-top: 30px;
+ padding-top: 30px;
}
+
.padding-bottom {
- padding-bottom: 30px;
+ padding-bottom: 30px;
}
+
.margin-right {
- margin-right: 30px;
+ margin-right: 30px;
}
+
.padding-none {
- padding: 0;
+ padding: 0;
}
+
.btn {
- padding: 20px;
- margin: 0;
- border-color: #9FB80A;
- border-width: 2px;
- color: #9FB80A;;
+ padding: 20px;
+ margin: 0;
+ border-color: #9FB80A;
+ border-width: 2px;
+ color: #9FB80A;;
}
+
.btn:hover {
- border-color: #9FB80A;
+ border-color: #9FB80A;
}
+
.btn.delete {
- border-color: #aaaaaa;
- color: #aaaaaa;
+ border-color: #aaaaaa;
+ color: #aaaaaa;
}
+
.btn.delete:hover {
- border-color: #aaaaaa;
- color: red;
+ border-color: #aaaaaa;
+ color: red;
}
+
.glyphicon {
- margin-right: 10px;
+ margin-right: 10px;
}
+
.top-menu {
- padding-top: 30px;
- padding-bottom: 30px;
+ padding-top: 30px;
+ padding-bottom: 30px;
}
+
.top-menu p {
- margin-bottom: 0;
- line-height: 16px;
+ margin-bottom: 0;
+ line-height: 16px;
}
+
.top-menu a {
- margin-bottom: 0;
- line-height: 16px;
- font-size: 16px;
- color: #7B7573;
- font-weight: 400;
+ margin-bottom: 0;
+ line-height: 16px;
+ font-size: 16px;
+ color: #7B7573;
+ font-weight: 400;
}
+
.divider {
- height: 15px;
+ height: 15px;
}
+
.divider.blue {
- background-color: #42C3C9;
+ background-color: #42C3C9;
}
+
.divider.green {
- background-color: #9FB80A;
+ background-color: #9FB80A;
}
+
.banner.main {
- height: 150px;
- background: url("/static/top-banner.jpg");
- background-position: right;
- background-repeat: no-repeat;
- background-size: cover;
+ height: 150px;
+ background: url("/static/top-banner.jpg");
+ background-position: right;
+ background-repeat: no-repeat;
+ background-size: cover;
+ border-bottom: solid 15px #42c3c9;
+ margin-bottom: 15px;
}
+
.banner.menu {
- height: 150px;
- background-color: #E1E17F;
+ background-color: #E1E17F;
}
+
.banner.profile {
- height: 150px;
- background-color: #A6E8EB;
+ height: 150px;
+ background-color: #A6E8EB;
}
+
.banner h1 {
- margin: 45px 0;
+ margin: 45px 0;
+ font-size: 14px;
}
- .restaurant-list {
- background-color: #F0F0F0;
- padding: 20px;
-u }
- .restaurant-list:hover {
- background-color: #e1e17f;
- padding: 20px;
+
+.restaurant-list {
+ background-color: #F0F0F0;
+ padding: 20px;
}
+
+.restaurant-list:hover {
+ background-color: #e1e17f;
+ padding: 20px;
+}
+
.menu-item {
- background: #F0F0F0;
- padding: 20px;
- margin: 20px;
- margin-left: -20px;
+ background: #F0F0F0;
+ padding: 20px;
+ margin: 20px;
+ margin-left: -20px;
}
+
.menu-price {
- font-weight: 700;
+ font-weight: 700;
}
+
.creator {
- padding-right: 20px;
- margin-top: -20px;
- text-align: right;
- float:right;
+ padding-right: 20px;
+ margin-top: -20px;
+ text-align: right;
+ float: right;
}
+
.creator img {
- width: 100px;
- border-radius: 50%;
+ width: 100px;
+ border-radius: 50%;
}
+
.creator figcaption {
- font-size: 14px;
- color: #7B7573;
- font-weight: 400;
- margin-top: -20px;
+ font-size: 14px;
+ color: #7B7573;
+ font-weight: 400;
+ margin-top: -20px;
}
+
.flash {
- background-color: #98FB98;
- width:100%;
- text-decoration: none;
+ background-color: #98FB98;
+ width: 100%;
+ text-decoration: none;
}
.flash li {
- list-style-type: none;
- text-align: center;
+ list-style-type: none;
+ text-align: center;
}
\ No newline at end of file
diff --git a/Lesson4/step2/templates/deleteRestaurant.html b/Lesson4/step2/templates/deleteRestaurant.html
index f71b37a..20eb995 100644
--- a/Lesson4/step2/templates/deleteRestaurant.html
+++ b/Lesson4/step2/templates/deleteRestaurant.html
@@ -1,17 +1,19 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
- Are you sure you want to delete {{restaurant.name}}?
+ {% include "header.html" %}
+ Are you sure you want to delete {{ restaurant.name }}?
-
+
{% endblock %}
\ No newline at end of file
diff --git a/Lesson4/step2/templates/deletemenuitem.html b/Lesson4/step2/templates/deletemenuitem.html
index e49fd4a..bcef025 100644
--- a/Lesson4/step2/templates/deletemenuitem.html
+++ b/Lesson4/step2/templates/deletemenuitem.html
@@ -1,17 +1,19 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
- Are you sure you want to delete {{item.name}}?
+ {% include "header.html" %}
+ Are you sure you want to delete {{ item.name }}?
-
+
{% endblock %}
diff --git a/Lesson4/step2/templates/editRestaurant.html b/Lesson4/step2/templates/editRestaurant.html
index 5ce142f..cd6cc37 100644
--- a/Lesson4/step2/templates/editRestaurant.html
+++ b/Lesson4/step2/templates/editRestaurant.html
@@ -1,29 +1,31 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
+ {% include "header.html" %}
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/Lesson4/step2/templates/editmenuitem.html b/Lesson4/step2/templates/editmenuitem.html
index e92fee7..41e0e02 100644
--- a/Lesson4/step2/templates/editmenuitem.html
+++ b/Lesson4/step2/templates/editmenuitem.html
@@ -1,58 +1,65 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
{% endblock %}
\ No newline at end of file
diff --git a/Lesson4/step2/templates/header.html b/Lesson4/step2/templates/header.html
index e706801..1f7f1bb 100644
--- a/Lesson4/step2/templates/header.html
+++ b/Lesson4/step2/templates/header.html
@@ -1,15 +1,15 @@
\ No newline at end of file
diff --git a/Lesson4/step2/templates/login.html b/Lesson4/step2/templates/login.html
index ba2472a..ab7c7bc 100644
--- a/Lesson4/step2/templates/login.html
+++ b/Lesson4/step2/templates/login.html
@@ -1,147 +1,128 @@
-
+{% extends "main.html" %}
+{% block content %}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+ Login with Facebook
+
+
+
+{% endblock %}
+
+{% block scripts %}
+
+
+
+
+
+{% endblock %}
diff --git a/Lesson4/step2/templates/main.html b/Lesson4/step2/templates/main.html
index 75de0c9..da8af1a 100644
--- a/Lesson4/step2/templates/main.html
+++ b/Lesson4/step2/templates/main.html
@@ -1,14 +1,21 @@
-
-
-
-
-
-
-
- {% block content %}
- {% endblock %}
-
-
+
+
+
+
+ {% block css %}
+ {% endblock %}
+
+
+
+ {% block content %}
+ {% endblock %}
+
+{% block scripts %}
+{% endblock %}
+
\ No newline at end of file
diff --git a/Lesson4/step2/templates/menu.html b/Lesson4/step2/templates/menu.html
index b56a5f1..2b7c576 100644
--- a/Lesson4/step2/templates/menu.html
+++ b/Lesson4/step2/templates/menu.html
@@ -1,114 +1,133 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
- {% with messages = get_flashed_messages() %}
- {% if messages %}
-
-
- {% for message in messages %}
- {{ message }}
- {% endfor %}
-
- {% endif %}
- {% endwith %}
+
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
-
-
-
- {% if items !=[] %}
-
-
-
-
Appetizers
- {% for i in items %}
- {% if i.course == 'Appetizer' %}
-
- {% endif %}
- {% endfor %}
-
-
-
Entrees
- {% for i in items %}
- {% if i.course == 'Entree' %}
-
- {% endif %}
- {% endfor %}
-
-
-
Desserts
- {% for i in items %}
- {% if i.course == 'Dessert' %}
-
- {% endif %}
- {% endfor %}
- Beverages
- {% for i in items %}
- {% if i.course == 'Beverage' %}
-
- {% endif %}
- {% endfor %}
-
-
-
- {% endif %}
+
+ {% for message in messages %}
+ {{ message }}
+ {% endfor %}
+
+ {% endif %}
+ {% endwith %}
+
+
+ {% if login_session.user_id == restaurant.user_id %}
+
+ {% endif %}
+
+ {% if items !=[] %}
+
+
+
+
Appetizers
+ {% for i in items %}
+ {% if i.course == 'Appetizer' %}
+
+ {% endif %}
+ {% endfor %}
+
+
+
Entrees
+ {% for i in items %}
+ {% if i.course == 'Entree' %}
+
+ {% endif %}
+ {% endfor %}
+
+
+
Desserts
+ {% for i in items %}
+ {% if i.course == 'Dessert' %}
+
+ {% endif %}
+ {% endfor %}
+ Beverages
+ {% for i in items %}
+ {% if i.course == 'Beverage' %}
+
+ {% endif %}
+ {% endfor %}
+
+
+
+ {% endif %}
{% endblock %}
diff --git a/Lesson4/step2/templates/newRestaurant.html b/Lesson4/step2/templates/newRestaurant.html
index 978cfd4..e98e1ff 100644
--- a/Lesson4/step2/templates/newRestaurant.html
+++ b/Lesson4/step2/templates/newRestaurant.html
@@ -1,25 +1,26 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
+ {% include "header.html" %}
+
+
+
{% endblock %}
diff --git a/Lesson4/step2/templates/newmenuitem.html b/Lesson4/step2/templates/newmenuitem.html
index 88a1d51..25b6c67 100644
--- a/Lesson4/step2/templates/newmenuitem.html
+++ b/Lesson4/step2/templates/newmenuitem.html
@@ -1,55 +1,57 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
{% endblock %}
diff --git a/Lesson4/step2/templates/publicmenu.html b/Lesson4/step2/templates/publicmenu.html
deleted file mode 100644
index ac6dc5d..0000000
--- a/Lesson4/step2/templates/publicmenu.html
+++ /dev/null
@@ -1,95 +0,0 @@
-{% extends "main.html" %}
-{% block content %}
-{% include "header.html" %}
-
-
-
-
-
-
- {% with messages = get_flashed_messages() %}
- {% if messages %}
-
- {% for message in messages %}
- {{ message }}
- {% endfor %}
-
- {% endif %}
- {% endwith %}
-
-
- {% if items !=[] %}
-
-
-
-
Appetizers
- {% for i in items %}
- {% if i.course == 'Appetizer' %}
-
- {% endif %}
- {% endfor %}
-
-
-
Entrees
- {% for i in items %}
- {% if i.course == 'Entree' %}
-
- {% endif %}
- {% endfor %}
-
-
-
Desserts
- {% for i in items %}
- {% if i.course == 'Dessert' %}
-
- {% endif %}
- {% endfor %}
- Beverages
- {% for i in items %}
- {% if i.course == 'Beverage' %}
-
- {% endif %}
- {% endfor %}
-
-
-
- {% endif %}
-{% endblock %}
diff --git a/Lesson4/step2/templates/publicrestaurants.html b/Lesson4/step2/templates/publicrestaurants.html
deleted file mode 100644
index 63c4ec7..0000000
--- a/Lesson4/step2/templates/publicrestaurants.html
+++ /dev/null
@@ -1,53 +0,0 @@
-{% extends "main.html" %}
-{% block content %}
-
-
-
-
-
- {% with messages = get_flashed_messages() %}
- {% if messages %}
-
-
- {% for message in messages %}
- {{ message }}
- {% endfor %}
-
- {% endif %}
- {% endwith %}
-
-
-
-
-
-
- {% for restaurant in restaurants %}
-
-
-
-
-
{{restaurant.name}}
-
-
-
-
- {% endfor %}
-{% endblock %}
diff --git a/Lesson4/step2/templates/restaurants.html b/Lesson4/step2/templates/restaurants.html
index 33de351..12d7193 100644
--- a/Lesson4/step2/templates/restaurants.html
+++ b/Lesson4/step2/templates/restaurants.html
@@ -1,55 +1,62 @@
{% extends "main.html" %}
{% block content %}
-{% include "header.html" %}
-
-
-
+ {% include "header.html" %}
+
+
+
-
- {% with messages = get_flashed_messages() %}
- {% if messages %}
-
-
- {% for message in messages %}
- {{ message }}
- {% endfor %}
-
- {% endif %}
- {% endwith %}
+
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
-
-
-
- {% for restaurant in restaurants %}
-
-
-
-
-
{{restaurant.name}}
-
-
-
-
- {% endfor %}
+
+ {% for message in messages %}
+ {{ message }}
+ {% endfor %}
+
+ {% endif %}
+ {% endwith %}
+
+
+ {% if login_session.user_id %}
+
+ {% endif %}
+ {% for restaurant in restaurants %}
+
+
+
+
+
+ {% if login_session.user_id == restaurant.user_id %}
+
+ {% endif %}
+ {{ restaurant.name }}
+
+
+
+
+
+
+ {% endfor %}
{% endblock %}
diff --git a/Lesson4/step2/variables.py b/Lesson4/step2/variables.py
new file mode 100644
index 0000000..b7c6fdd
--- /dev/null
+++ b/Lesson4/step2/variables.py
@@ -0,0 +1,47 @@
+from os import environ
+
+from dotenv import load_dotenv, find_dotenv
+
+load_dotenv(find_dotenv())
+
+google_web = dict(
+ client_id=environ.get("google_client_id", "google_client_id_here"),
+ project_id=environ.get("google_project_id", "google_project_id_here"),
+ auth_uri=environ.get(
+ "google_auth_uri",
+ "https://accounts.google.com/o/oauth2/auth"
+ ),
+ token_uri=environ.get(
+ "google_token_uri",
+ "https://accounts.google.com/o/oauth2/token"
+ ),
+ auth_provider_x509_cert_url=environ.get(
+ "google_x509",
+ "https://www.googleapis.com/oauth2/v1/certs"
+ ),
+ client_secret=environ.get(
+ "google_client_secret",
+ "google_client_secret_here"
+ ),
+ javascript_origins=[
+ "http://localhost:5000"
+ ],
+ scope='',
+ redirect_uris=[
+ "https://localhost:5000/callback",
+ "http://localhost:5000/callback"
+ ]
+)
+
+facebook_web = dict(
+ app_id=environ.get('facebook_app_id', 'facebook_app_id_goes_here'),
+ app_secret=environ.get(
+ 'facebook_app_secret',
+ 'facebook_app_secret_goes_here'
+ )
+)
+
+main_app = dict(
+ secret_key=environ.get('app_secret_key', 'super secret key'),
+ debug=environ.get('debug', True)
+)