Update app.py
Browse files
app.py
CHANGED
|
@@ -78,7 +78,57 @@ def login():
|
|
| 78 |
return render_template("login.html", error=f"Error: {str(e)}")
|
| 79 |
|
| 80 |
return render_template("login.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
@app.route("/menu", methods=["GET", "POST"])
|
| 83 |
def menu():
|
| 84 |
selected_category = request.args.get("category", "All")
|
|
@@ -102,6 +152,7 @@ def menu():
|
|
| 102 |
food_items = []
|
| 103 |
categories = []
|
| 104 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
@app.route("/cart", methods=["GET"])
|
|
|
|
| 78 |
return render_template("login.html", error=f"Error: {str(e)}")
|
| 79 |
|
| 80 |
return render_template("login.html")
|
| 81 |
+
@app.route("/menu", methods=["GET", "POST"])
|
| 82 |
+
def menu():
|
| 83 |
+
selected_category = request.args.get("category", "All")
|
| 84 |
+
user_id = session.get('user_id')
|
| 85 |
+
print(f"Cookies on /menu: {request.cookies}")
|
| 86 |
+
print(f"Session check in /menu: user_id={user_id}")
|
| 87 |
+
|
| 88 |
+
# Get the selected category from the query parameter, default is "All"
|
| 89 |
+
selected_category = request.args.get("category", "All")
|
| 90 |
+
print(f"Selected category: {selected_category}")
|
| 91 |
+
if not user_id:
|
| 92 |
+
print("Session missing, redirecting to login.")
|
| 93 |
+
return redirect(url_for('login'))
|
| 94 |
+
|
| 95 |
|
| 96 |
+
try:
|
| 97 |
+
query = """
|
| 98 |
+
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c
|
| 99 |
+
FROM Menu_Item__c
|
| 100 |
+
"""
|
| 101 |
+
# Query to fetch menu items
|
| 102 |
+
result = sf.query(query)
|
| 103 |
+
|
| 104 |
+
# Fetch all food items from the query result
|
| 105 |
+
food_items = result['records'] if 'records' in result else []
|
| 106 |
+
|
| 107 |
+
# Dynamically determine categories based on the fetched data
|
| 108 |
+
categories = {item.get("Veg_NonVeg__c").capitalize() for item in food_items if item.get("Veg_NonVeg__c")}
|
| 109 |
+
categories = {"Veg", "Non-Veg"} # Explicitly overwrite to ensure valid categories only
|
| 110 |
+
|
| 111 |
+
# Filter food items based on the selected category
|
| 112 |
+
if selected_category == "Veg":
|
| 113 |
+
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
| 114 |
+
elif selected_category == "Non-Veg":
|
| 115 |
+
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
| 116 |
+
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(f"Error fetching menu data: {str(e)}")
|
| 119 |
+
food_items = []
|
| 120 |
+
categories = {"All", "Veg", "Non-Veg"} # Default categories on error
|
| 121 |
+
|
| 122 |
+
# Render the menu page with the filtered data
|
| 123 |
+
return render_template(
|
| 124 |
+
"menu.html",
|
| 125 |
+
food_items=food_items,
|
| 126 |
+
categories=sorted(categories), # Sort categories alphabetically if needed
|
| 127 |
+
selected_category=selected_category,
|
| 128 |
+
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
"""
|
| 132 |
@app.route("/menu", methods=["GET", "POST"])
|
| 133 |
def menu():
|
| 134 |
selected_category = request.args.get("category", "All")
|
|
|
|
| 152 |
food_items = []
|
| 153 |
categories = []
|
| 154 |
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
| 155 |
+
"""
|
| 156 |
|
| 157 |
|
| 158 |
@app.route("/cart", methods=["GET"])
|