nagasurendra commited on
Commit
0dbc391
·
verified ·
1 Parent(s): d934384

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +20 -17
menu.py CHANGED
@@ -8,7 +8,9 @@ sf = get_salesforce_connection()
8
 
9
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
10
  def menu():
11
- selected_category = request.args.get("category", "All")
 
 
12
  user_email = session.get('user_email')
13
 
14
  if not user_email:
@@ -62,6 +64,16 @@ def menu():
62
  # Merge both Menu_Item__c and Custom_Dish__c records into the ordered menu
63
  all_items = food_items + custom_dishes
64
 
 
 
 
 
 
 
 
 
 
 
65
  # Define the order of sections, adding "Best Sellers" at the top
66
  section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
67
  ordered_menu = {section: [] for section in section_order}
@@ -69,11 +81,6 @@ def menu():
69
  # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
70
  best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
71
 
72
- if selected_category == "Veg":
73
- best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
74
- elif selected_category == "Non veg":
75
- best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
76
-
77
  # Take only the top 4 best sellers after filtering
78
  best_sellers = best_sellers[:4]
79
 
@@ -84,7 +91,7 @@ def menu():
84
  # Create a set to track item names already added to prevent duplicates
85
  added_item_names = set()
86
 
87
- # Filter and organize menu items based on category and section (to avoid duplicates)
88
  for item in all_items:
89
  section = item.get("Section__c", "Others") # Default to "Others" if missing
90
  if section not in ordered_menu:
@@ -94,20 +101,13 @@ def menu():
94
  if item['Name'] in added_item_names:
95
  continue
96
 
97
- # Apply category filters
98
- if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
99
- continue
100
- if selected_category == "Non veg" and item.get("Veg_NonVeg__c") not in ["Non veg", "both"]:
101
- continue
102
-
103
  ordered_menu[section].append(item)
104
  added_item_names.add(item['Name']) # Add item to the set of added items
105
- print(f"Added item to {section}: {item['Name']}") # Debugging
106
 
107
  # Remove empty sections
108
  ordered_menu = {section: items for section, items in ordered_menu.items() if items}
109
- print(f"Final ordered menu: {ordered_menu.keys()}") # Debugging
110
 
 
111
  categories = ["All", "Veg", "Non veg"]
112
 
113
  except Exception as e:
@@ -117,17 +117,20 @@ def menu():
117
  referral_code = 'N/A'
118
  reward_points = 0
119
 
120
- # Pass the user's first letter (first_letter) to the template
121
  return render_template(
122
  "menu.html",
123
  ordered_menu=ordered_menu,
124
  categories=categories,
125
- selected_category=selected_category,
 
 
126
  referral_code=referral_code,
127
  reward_points=reward_points,
128
  user_name=user_name, # Pass name to the template
129
  first_letter=first_letter # Pass first letter to the template
130
  )
 
131
  @menu_blueprint.route('/api/addons', methods=['GET'])
132
  def get_addons():
133
  item_name = request.args.get('item_name')
 
8
 
9
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
10
  def menu():
11
+ # Get the current toggle status from the query string (False if not set)
12
+ veg_selected = request.args.get("veg", "off") == "on"
13
+ customized_dish_selected = request.args.get("customized_dish", "off") == "on"
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
+ # Apply filtering based on toggles
68
+ if veg_selected:
69
+ all_items = [item for item in all_items if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
70
+ if customized_dish_selected:
71
+ all_items = [item for item in all_items if item.get("Section__c") == "Customized dish"]
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
  # 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
  # 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
  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
  referral_code = 'N/A'
118
  reward_points = 0
119
 
120
+ # Pass the necessary variables to the template
121
  return render_template(
122
  "menu.html",
123
  ordered_menu=ordered_menu,
124
  categories=categories,
125
+ veg_selected=veg_selected,
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
  @menu_blueprint.route('/api/addons', methods=['GET'])
135
  def get_addons():
136
  item_name = request.args.get('item_name')