Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -273,59 +273,56 @@ def login():
|
|
273 |
return render_template("menu.html", user_name=user_name)
|
274 |
@app.route("/menu", methods=["GET", "POST"])
|
275 |
def menu():
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
session["user_name"] = request.args.get("name")
|
280 |
-
session.modified = True
|
281 |
-
print(f"User auto-logged in: {session['user_email']} - {session['user_name']}")
|
282 |
|
283 |
-
|
284 |
-
user_name = session.get("user_name")
|
285 |
|
286 |
-
if not
|
287 |
-
print("
|
288 |
-
return redirect(url_for(
|
289 |
|
290 |
try:
|
291 |
-
# Fetch referral
|
292 |
-
user_query = f""
|
293 |
-
SELECT Referral__c, Reward_Points__c
|
294 |
-
FROM Customer_Login__c
|
295 |
-
WHERE Email__c = '{user_email}'
|
296 |
-
"""
|
297 |
user_result = sf.query(user_query)
|
298 |
-
user_data = user_result.get("records", [{}])[0]
|
299 |
|
300 |
-
|
301 |
-
|
|
|
|
|
|
|
|
|
302 |
|
303 |
-
# Fetch menu items
|
304 |
menu_query = """
|
305 |
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c
|
306 |
FROM Menu_Item__c
|
307 |
"""
|
308 |
-
|
309 |
-
food_items =
|
310 |
|
311 |
-
#
|
312 |
-
categories = {"
|
313 |
-
|
314 |
|
|
|
315 |
if selected_category == "Veg":
|
316 |
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
317 |
elif selected_category == "Non-Veg":
|
318 |
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
319 |
|
320 |
except Exception as e:
|
321 |
-
print(f"Error fetching menu data: {str(e)}")
|
|
|
322 |
food_items = []
|
323 |
-
|
|
|
324 |
reward_points = 0
|
325 |
|
326 |
return render_template(
|
327 |
"menu.html",
|
328 |
-
user_name=user_name,
|
329 |
food_items=food_items,
|
330 |
categories=sorted(categories),
|
331 |
selected_category=selected_category,
|
|
|
273 |
return render_template("menu.html", user_name=user_name)
|
274 |
@app.route("/menu", methods=["GET", "POST"])
|
275 |
def menu():
|
276 |
+
selected_category = request.args.get("category", "All")
|
277 |
+
user_id = session.get('user_id')
|
278 |
+
user_email = session.get('user_email')
|
|
|
|
|
|
|
279 |
|
280 |
+
print_session() # Debugging session info
|
|
|
281 |
|
282 |
+
if not user_id or not user_email:
|
283 |
+
print("❌ Session missing, redirecting to login.")
|
284 |
+
return redirect(url_for('login'))
|
285 |
|
286 |
try:
|
287 |
+
# ✅ Fetch user referral & reward points
|
288 |
+
user_query = f"SELECT Referral__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
|
|
|
|
|
|
|
|
|
289 |
user_result = sf.query(user_query)
|
|
|
290 |
|
291 |
+
if not user_result['records']:
|
292 |
+
print("❌ User not found in Salesforce, redirecting to login.")
|
293 |
+
return redirect(url_for('login'))
|
294 |
+
|
295 |
+
referral_code = user_result['records'][0].get('Referral__c', 'N/A') # Default 'N/A'
|
296 |
+
reward_points = user_result['records'][0].get('Reward_Points__c', 0) # Default 0
|
297 |
|
298 |
+
# ✅ Fetch menu items
|
299 |
menu_query = """
|
300 |
SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c
|
301 |
FROM Menu_Item__c
|
302 |
"""
|
303 |
+
result = sf.query(menu_query)
|
304 |
+
food_items = result['records'] if 'records' in result else []
|
305 |
|
306 |
+
# ✅ Filter categories dynamically
|
307 |
+
categories = {item.get("Veg_NonVeg__c").capitalize() for item in food_items if item.get("Veg_NonVeg__c")}
|
308 |
+
categories = {"Veg", "Non-Veg"} # Ensure valid categories only
|
309 |
|
310 |
+
# ✅ Filter items based on selected category
|
311 |
if selected_category == "Veg":
|
312 |
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
313 |
elif selected_category == "Non-Veg":
|
314 |
food_items = [item for item in food_items if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
315 |
|
316 |
except Exception as e:
|
317 |
+
print(f"❌ Error fetching menu data: {str(e)}")
|
318 |
+
print(traceback.format_exc()) # Show full error traceback
|
319 |
food_items = []
|
320 |
+
categories = {"All", "Veg", "Non-Veg"}
|
321 |
+
referral_code = 'N/A'
|
322 |
reward_points = 0
|
323 |
|
324 |
return render_template(
|
325 |
"menu.html",
|
|
|
326 |
food_items=food_items,
|
327 |
categories=sorted(categories),
|
328 |
selected_category=selected_category,
|