Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,30 +26,6 @@ app.config["SESSION_PERMANENT"] = False # Do not use permanent sessions
|
|
| 26 |
app.session_interface = SecureCookieSessionInterface()
|
| 27 |
print("Session interface configured.")
|
| 28 |
|
| 29 |
-
@app.route("/menu", methods=["GET", "POST"])
|
| 30 |
-
def menu():
|
| 31 |
-
print(f"Cookies on /menu: {request.cookies}")
|
| 32 |
-
selected_category = request.args.get("category", "All")
|
| 33 |
-
user_id = session.get('user_id')
|
| 34 |
-
print(f"Session check in /menu: user_id={user_id}")
|
| 35 |
-
|
| 36 |
-
if not user_id:
|
| 37 |
-
print("Session missing, redirecting to login.")
|
| 38 |
-
return redirect(url_for('login'))
|
| 39 |
-
|
| 40 |
-
try:
|
| 41 |
-
query = "SELECT Name, Price__c, Image1__c, Category__c, Description__c FROM Menu_Item__c"
|
| 42 |
-
result = sf.query(query)
|
| 43 |
-
food_items = result['records'] if 'records' in result else []
|
| 44 |
-
categories = {item['Category__c'] for item in food_items if 'Category__c' in item}
|
| 45 |
-
if selected_category != "All":
|
| 46 |
-
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error fetching menu data: {str(e)}")
|
| 49 |
-
food_items = []
|
| 50 |
-
categories = []
|
| 51 |
-
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
| 52 |
-
|
| 53 |
@app.route("/cart", methods=["GET"])
|
| 54 |
def cart():
|
| 55 |
email = session.get('user_email') # Get logged-in user's email
|
|
@@ -104,9 +80,10 @@ def update_quantity():
|
|
| 104 |
cart_items = result["records"]
|
| 105 |
subtotal = sum(item['Quantity__c'] * item['Price__c'] for item in cart_items)
|
| 106 |
|
| 107 |
-
return jsonify({"success": True, "new_quantity": quantity, "subtotal": subtotal})
|
| 108 |
except Exception as e:
|
| 109 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 110 |
|
|
|
|
| 111 |
if __name__ == "__main__":
|
| 112 |
-
app.run(debug=False, host="0.0.0.0", port=7860)
|
|
|
|
| 26 |
app.session_interface = SecureCookieSessionInterface()
|
| 27 |
print("Session interface configured.")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@app.route("/cart", methods=["GET"])
|
| 30 |
def cart():
|
| 31 |
email = session.get('user_email') # Get logged-in user's email
|
|
|
|
| 80 |
cart_items = result["records"]
|
| 81 |
subtotal = sum(item['Quantity__c'] * item['Price__c'] for item in cart_items)
|
| 82 |
|
| 83 |
+
return jsonify({"success": True, "new_quantity": quantity, "subtotal": subtotal, "new_price": item_price * quantity})
|
| 84 |
except Exception as e:
|
| 85 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 86 |
|
| 87 |
+
|
| 88 |
if __name__ == "__main__":
|
| 89 |
+
app.run(debug=False, host="0.0.0.0", port=7860)
|