Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from cart import cart_blueprint # Same for other blueprints
|
|
10 |
from order import order_blueprint # Same for user blueprint
|
11 |
from orderhistory import orderhistory_blueprint
|
12 |
from user_details import user_details_blueprint
|
|
|
13 |
from datetime import datetime
|
14 |
from datetime import datetime
|
15 |
import pytz # Library to handle timezone conversions
|
@@ -40,6 +41,7 @@ app.register_blueprint(user_details_blueprint, url_prefix='/user')
|
|
40 |
app.register_blueprint(menu_blueprint)
|
41 |
app.register_blueprint(order_blueprint)
|
42 |
app.register_blueprint(orderhistory_blueprint, url_prefix='/orderhistory')
|
|
|
43 |
|
44 |
|
45 |
|
@@ -62,105 +64,6 @@ def home():
|
|
62 |
|
63 |
return render_template("index.html")
|
64 |
|
65 |
-
@app.route("/generate_custom_dish", methods=["POST"])
|
66 |
-
def generate_custom_dish():
|
67 |
-
try:
|
68 |
-
data = request.form
|
69 |
-
dish_name = data.get("name")
|
70 |
-
description = data.get("description")
|
71 |
-
item_image_url = "https://huggingface.co/spaces/nagasurendra/BiryaniHubflask30/resolve/main/static/customized.jpg"
|
72 |
-
item_image_url2 = "https://huggingface.co/spaces/nagasurendra/BiryaniHubflask30/resolve/main/static/customized1.jpg"
|
73 |
-
|
74 |
-
if not dish_name or not description:
|
75 |
-
return jsonify({"success": False, "error": "Both fields are required"}), 400
|
76 |
-
|
77 |
-
# Generate a random price for the custom dish
|
78 |
-
price = random.randint(10, 30) # Example logic for price setting
|
79 |
-
|
80 |
-
# Determine Veg/Non-Veg
|
81 |
-
veg_keywords = ["paneer", "vegetable", "mushroom", "cheese"]
|
82 |
-
non_veg_keywords = ["chicken", "mutton", "fish", "egg"]
|
83 |
-
|
84 |
-
category = "Veg" if any(word in description.lower() for word in veg_keywords) else \
|
85 |
-
"Non veg" if any(word in description.lower() for word in non_veg_keywords) else \
|
86 |
-
"both"
|
87 |
-
|
88 |
-
# Query to check if the dish already exists in Salesforce (Custom_Dish__c object)
|
89 |
-
existing_dish_query = f"SELECT Id, Name, Price__c, Image1__c, Image2__c, Description__c, Veg_NonVeg__c FROM Custom_Dish__c WHERE Name = '{dish_name}'"
|
90 |
-
existing_dish_result = sf.query(existing_dish_query)
|
91 |
-
|
92 |
-
if existing_dish_result['totalSize'] > 0:
|
93 |
-
# If the dish exists, use the existing details
|
94 |
-
existing_dish = existing_dish_result['records'][0]
|
95 |
-
price = existing_dish['Price__c']
|
96 |
-
item_image_url = existing_dish['Image1__c']
|
97 |
-
item_image_url2 = existing_dish['Image2__c']
|
98 |
-
category = existing_dish['Veg_NonVeg__c']
|
99 |
-
else:
|
100 |
-
# If the dish does not exist, create a new custom dish
|
101 |
-
custom_dish = {
|
102 |
-
'Name': dish_name,
|
103 |
-
'Price__c': price,
|
104 |
-
'Image1__c': item_image_url,
|
105 |
-
'Image2__c': item_image_url2,
|
106 |
-
'Description__c': description,
|
107 |
-
'Veg_NonVeg__c': category,
|
108 |
-
'Section__c': 'Customized dish',
|
109 |
-
'Total_Ordered__c': 0
|
110 |
-
}
|
111 |
-
|
112 |
-
# Insert the custom dish into Salesforce (Custom_Dish__c object)
|
113 |
-
result = sf.Custom_Dish__c.create(custom_dish)
|
114 |
-
|
115 |
-
if not result.get('success'):
|
116 |
-
return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
|
117 |
-
|
118 |
-
# After ensuring the dish exists, check if it's already in the Cart_Item__c
|
119 |
-
email = session.get('user_email') # Assuming you have the user's email in session
|
120 |
-
|
121 |
-
# Query to check if the custom dish already exists in the cart for the logged-in user
|
122 |
-
cart_item_query = f"SELECT Id, Quantity__c, Price__c, Base_Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{dish_name}'"
|
123 |
-
cart_item_result = sf.query(cart_item_query)
|
124 |
-
|
125 |
-
if cart_item_result['totalSize'] > 0:
|
126 |
-
# If the custom dish is already in the cart, update the quantity and price
|
127 |
-
cart_item = cart_item_result['records'][0]
|
128 |
-
new_quantity = cart_item['Quantity__c'] + 1 # Increase quantity by 1
|
129 |
-
new_price = price * new_quantity # Update price based on new quantity
|
130 |
-
|
131 |
-
# Update the cart item in Salesforce
|
132 |
-
updated_cart_item = {
|
133 |
-
'Quantity__c': new_quantity,
|
134 |
-
'Price__c': new_price
|
135 |
-
}
|
136 |
-
|
137 |
-
cart_item_update = sf.Cart_Item__c.update(cart_item['Id'], updated_cart_item)
|
138 |
-
|
139 |
-
else:
|
140 |
-
# If the custom dish is not in the cart, create a new cart item
|
141 |
-
cart_item = {
|
142 |
-
'Name': dish_name,
|
143 |
-
'Price__c': price,
|
144 |
-
'Base_Price__c': price,
|
145 |
-
'Image1__c': item_image_url,
|
146 |
-
'Quantity__c': 1, # Default quantity is 1
|
147 |
-
'Add_Ons__c': '', # Set Add_ons__c to empty
|
148 |
-
'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
|
149 |
-
'Customer_Email__c': email # Associate the custom dish with the logged-in user
|
150 |
-
}
|
151 |
-
|
152 |
-
# Insert the custom dish as a Cart_Item__c record in Salesforce
|
153 |
-
cart_result = sf.Cart_Item__c.create(cart_item)
|
154 |
-
|
155 |
-
# Redirect to the cart page after successfully adding or updating the cart item
|
156 |
-
return redirect(url_for("cart"))
|
157 |
-
|
158 |
-
except Exception as e:
|
159 |
-
return jsonify({"success": False, "error": str(e)}), 500
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
app.permanent_session_lifetime = timedelta(minutes=5)
|
165 |
@app.before_request
|
166 |
def check_session_timeout():
|
@@ -193,12 +96,5 @@ def logout():
|
|
193 |
# Pass table number to redirect page
|
194 |
return render_template("redirect_page.html", table_number=table_number)
|
195 |
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
if __name__ == "__main__":
|
204 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
10 |
from order import order_blueprint # Same for user blueprint
|
11 |
from orderhistory import orderhistory_blueprint
|
12 |
from user_details import user_details_blueprint
|
13 |
+
from customdish import customdish_blueprint
|
14 |
from datetime import datetime
|
15 |
from datetime import datetime
|
16 |
import pytz # Library to handle timezone conversions
|
|
|
41 |
app.register_blueprint(menu_blueprint)
|
42 |
app.register_blueprint(order_blueprint)
|
43 |
app.register_blueprint(orderhistory_blueprint, url_prefix='/orderhistory')
|
44 |
+
app.register_blueprint(customdish_blueprint, url_prefix='/customdish')
|
45 |
|
46 |
|
47 |
|
|
|
64 |
|
65 |
return render_template("index.html")
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
app.permanent_session_lifetime = timedelta(minutes=5)
|
68 |
@app.before_request
|
69 |
def check_session_timeout():
|
|
|
96 |
# Pass table number to redirect page
|
97 |
return render_template("redirect_page.html", table_number=table_number)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
if __name__ == "__main__":
|
100 |
app.run(debug=True, host="0.0.0.0", port=7860)
|