Spaces:
Runtime error
Runtime error
Update menu.py
Browse files
menu.py
CHANGED
@@ -8,9 +8,9 @@ sf = get_salesforce_connection()
|
|
8 |
|
9 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
10 |
def menu():
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
user_email = session.get('user_email')
|
15 |
|
16 |
if not user_email:
|
@@ -64,16 +64,6 @@ def menu():
|
|
64 |
# Merge both Menu_Item__c and Custom_Dish__c records into the ordered menu
|
65 |
all_items = food_items + custom_dishes
|
66 |
|
67 |
-
# Apply filtering based on toggles (Veg and Customized Dish)
|
68 |
-
if veg_selected:
|
69 |
-
all_items = [item for item in all_items if item.get("Veg_NonVeg__c") in ["Veg", "both"]] # Show only Veg items
|
70 |
-
if customized_dish_selected:
|
71 |
-
all_items = [item for item in all_items if item.get("Section__c") == "Customized dish"] # Show only Customized dishes
|
72 |
-
|
73 |
-
# Default to all items if both toggles are off
|
74 |
-
if not veg_selected and not customized_dish_selected:
|
75 |
-
all_items = food_items + custom_dishes # Show everything
|
76 |
-
|
77 |
# Define the order of sections, adding "Best Sellers" at the top
|
78 |
section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
|
79 |
ordered_menu = {section: [] for section in section_order}
|
@@ -81,6 +71,12 @@ def menu():
|
|
81 |
# Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
|
82 |
best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
# Take only the top 4 best sellers after filtering
|
85 |
best_sellers = best_sellers[:4]
|
86 |
|
@@ -91,7 +87,7 @@ def menu():
|
|
91 |
# Create a set to track item names already added to prevent duplicates
|
92 |
added_item_names = set()
|
93 |
|
94 |
-
# Filter and organize menu items based on section (to avoid duplicates)
|
95 |
for item in all_items:
|
96 |
section = item.get("Section__c", "Others") # Default to "Others" if missing
|
97 |
if section not in ordered_menu:
|
@@ -101,13 +97,18 @@ def menu():
|
|
101 |
if item['Name'] in added_item_names:
|
102 |
continue
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
ordered_menu[section].append(item)
|
105 |
added_item_names.add(item['Name']) # Add item to the set of added items
|
106 |
|
107 |
# Remove empty sections
|
108 |
ordered_menu = {section: items for section, items in ordered_menu.items() if items}
|
109 |
|
110 |
-
# Set categories for filtering
|
111 |
categories = ["All", "Veg", "Non veg"]
|
112 |
|
113 |
except Exception as e:
|
@@ -117,21 +118,22 @@ def menu():
|
|
117 |
referral_code = 'N/A'
|
118 |
reward_points = 0
|
119 |
|
120 |
-
#
|
|
|
|
|
|
|
121 |
return render_template(
|
122 |
"menu.html",
|
123 |
ordered_menu=ordered_menu,
|
124 |
categories=categories,
|
125 |
-
|
126 |
-
customized_dish_selected=customized_dish_selected,
|
127 |
-
selected_category="All", # Default category is All
|
128 |
referral_code=referral_code,
|
129 |
reward_points=reward_points,
|
130 |
user_name=user_name, # Pass name to the template
|
131 |
-
first_letter=first_letter # Pass first letter to the template
|
|
|
132 |
)
|
133 |
|
134 |
-
|
135 |
@menu_blueprint.route('/api/addons', methods=['GET'])
|
136 |
def get_addons():
|
137 |
item_name = request.args.get('item_name')
|
|
|
8 |
|
9 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
10 |
def menu():
|
11 |
+
selected_category = request.args.get("category", "All")
|
12 |
+
veg_toggle = request.args.get("veg-toggle", "off") # Handle the Veg toggle
|
13 |
+
customized_dish_toggle = request.args.get("customized-dish-toggle", "off") # Handle Customized Dish toggle
|
14 |
user_email = session.get('user_email')
|
15 |
|
16 |
if not user_email:
|
|
|
64 |
# Merge both Menu_Item__c and Custom_Dish__c records into the ordered menu
|
65 |
all_items = food_items + custom_dishes
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
# Define the order of sections, adding "Best Sellers" at the top
|
68 |
section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
|
69 |
ordered_menu = {section: [] for section in section_order}
|
|
|
71 |
# Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
|
72 |
best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
|
73 |
|
74 |
+
# Filter items by Veg if toggle is on
|
75 |
+
if veg_toggle == "on":
|
76 |
+
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
77 |
+
elif selected_category == "Non veg":
|
78 |
+
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
79 |
+
|
80 |
# Take only the top 4 best sellers after filtering
|
81 |
best_sellers = best_sellers[:4]
|
82 |
|
|
|
87 |
# Create a set to track item names already added to prevent duplicates
|
88 |
added_item_names = set()
|
89 |
|
90 |
+
# Filter and organize menu items based on category and section (to avoid duplicates)
|
91 |
for item in all_items:
|
92 |
section = item.get("Section__c", "Others") # Default to "Others" if missing
|
93 |
if section not in ordered_menu:
|
|
|
97 |
if item['Name'] in added_item_names:
|
98 |
continue
|
99 |
|
100 |
+
# Apply category filters
|
101 |
+
if veg_toggle == "on" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
|
102 |
+
continue
|
103 |
+
if selected_category == "Non veg" and item.get("Veg_NonVeg__c") not in ["Non veg", "both"]:
|
104 |
+
continue
|
105 |
+
|
106 |
ordered_menu[section].append(item)
|
107 |
added_item_names.add(item['Name']) # Add item to the set of added items
|
108 |
|
109 |
# Remove empty sections
|
110 |
ordered_menu = {section: items for section, items in ordered_menu.items() if items}
|
111 |
|
|
|
112 |
categories = ["All", "Veg", "Non veg"]
|
113 |
|
114 |
except Exception as e:
|
|
|
118 |
referral_code = 'N/A'
|
119 |
reward_points = 0
|
120 |
|
121 |
+
# If Customized Dish toggle is on, show the form
|
122 |
+
show_custom_dish_form = customized_dish_toggle == "on"
|
123 |
+
|
124 |
+
# Pass the user's first letter (first_letter) and other details to the template
|
125 |
return render_template(
|
126 |
"menu.html",
|
127 |
ordered_menu=ordered_menu,
|
128 |
categories=categories,
|
129 |
+
selected_category=selected_category,
|
|
|
|
|
130 |
referral_code=referral_code,
|
131 |
reward_points=reward_points,
|
132 |
user_name=user_name, # Pass name to the template
|
133 |
+
first_letter=first_letter, # Pass first letter to the template
|
134 |
+
show_custom_dish_form=show_custom_dish_form # Conditionally show the custom dish form
|
135 |
)
|
136 |
|
|
|
137 |
@menu_blueprint.route('/api/addons', methods=['GET'])
|
138 |
def get_addons():
|
139 |
item_name = request.args.get('item_name')
|