lokesh341 commited on
Commit
e4418e5
·
verified ·
1 Parent(s): c141bc3

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +20 -20
menu.py CHANGED
@@ -23,14 +23,19 @@ def get_valid_video_path(item_name, video_url=None):
23
  Get valid video path for item with placeholder fallback
24
  Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
25
  """
 
26
  if video_url:
 
27
  if video_url.startswith(('http://', 'https://')):
28
  return video_url
 
29
  elif video_url.startswith('/'):
30
  return video_url
 
31
  elif video_url.startswith('069'):
32
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
33
 
 
34
  if not os.path.exists(PLACEHOLDER_PATH):
35
  open(PLACEHOLDER_PATH, 'wb').close()
36
  print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
@@ -72,11 +77,10 @@ def menu():
72
  cart_count_result = sf.query(cart_query)
73
  cart_item_count = cart_count_result['totalSize']
74
 
75
- # Query to fetch Menu_Item__c records including additional fields
76
  menu_query = """
77
- SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
78
- Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c,
79
- All_Ingredients__c, Allergen__c, Nutritional_Information__c
80
  FROM Menu_Item__c
81
  """
82
  result = sf.query(menu_query)
@@ -87,16 +91,14 @@ def menu():
87
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
88
  item['Total_Ordered__c'] = 0
89
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
90
- # Ensure fields are present even if null
91
- item['All_Ingredients__c'] = item.get('All_Ingredients__c', 'Not specified')
92
- item['Allergen__c'] = item.get('Allergen__c', 'None')
93
- item['Nutritional_Information__c'] = item.get('Nutritional_Information__c', 'Not available')
94
 
95
- # Query to fetch Custom_Dish__c records including additional fields
96
  custom_dish_query = """
97
- SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
98
- Veg_NonVeg__c, Section__c, Total_Ordered__c,
99
- All_Ingredients__c, Allergen__c, Nutritional_Information__c
100
  FROM Custom_Dish__c
101
  WHERE CreatedDate >= LAST_N_DAYS:7
102
  """
@@ -108,9 +110,9 @@ def menu():
108
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
109
  item['Total_Ordered__c'] = 0
110
  item['Video1__c'] = get_valid_video_path(item['Name'])
111
- item['All_Ingredients__c'] = item.get('All_Ingredients__c', 'Not specified')
112
- item['Allergen__c'] = item.get('Allergen__c', 'None')
113
- item['Nutritional_Information__c'] = item.get('Nutritional_Information__c', 'Not available')
114
 
115
  # Merge both Menu_Item__c and Custom_Dish__c records
116
  all_items = food_items + custom_dishes
@@ -151,19 +153,18 @@ def menu():
151
 
152
  except Exception as e:
153
  print(f"Error fetching menu data: {str(e)}")
 
154
  ordered_menu = {section: [] for section in SECTION_ORDER}
155
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
156
  ordered_menu["Best Sellers"] = [{
157
  "Name": name,
158
  "Price__c": "12.99",
159
  "Description__c": f"Popular {name}",
 
160
  "Image1__c": "/static/placeholder.jpg",
161
  "Video1__c": get_valid_video_path(name),
162
  "Total_Ordered__c": 100,
163
- "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg",
164
- "All_Ingredients__c": "Not specified",
165
- "Allergen__c": "None",
166
- "Nutritional_Information__c": "Not available"
167
  } for name in best_sellers]
168
 
169
  categories = ["All", "Veg", "Non veg"]
@@ -183,7 +184,6 @@ def menu():
183
  cart_item_count=cart_item_count
184
  )
185
 
186
- # Rest of the routes remain unchanged
187
  @menu_blueprint.route('/api/addons', methods=['GET'])
188
  def get_addons():
189
  item_name = request.args.get('item_name')
 
23
  Get valid video path for item with placeholder fallback
24
  Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
25
  """
26
+ # First try: Video1__c from Salesforce if provided
27
  if video_url:
28
+ # If it's a complete URL (http/https)
29
  if video_url.startswith(('http://', 'https://')):
30
  return video_url
31
+ # If it's a relative path (/videos/xxx.mp4)
32
  elif video_url.startswith('/'):
33
  return video_url
34
+ # If it's a Salesforce File ID (starts with '069')
35
  elif video_url.startswith('069'):
36
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
37
 
38
+ # Final fallback: placeholder.mp4
39
  if not os.path.exists(PLACEHOLDER_PATH):
40
  open(PLACEHOLDER_PATH, 'wb').close()
41
  print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
 
77
  cart_count_result = sf.query(cart_query)
78
  cart_item_count = cart_count_result['totalSize']
79
 
80
+ # Query to fetch Menu_Item__c records including Ingredients__c
81
  menu_query = """
82
+ SELECT Name, Price__c, Description__c, Ingredients__c, Image1__c, Image2__c,
83
+ Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c
 
84
  FROM Menu_Item__c
85
  """
86
  result = sf.query(menu_query)
 
91
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
92
  item['Total_Ordered__c'] = 0
93
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
94
+ # Set default values for Ingredients__c and Description__c if null
95
+ item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
96
+ item['Description__c'] = item.get('Description__c', 'No description available')
 
97
 
98
+ # Query to fetch Custom_Dish__c records including Ingredients__c
99
  custom_dish_query = """
100
+ SELECT Name, Price__c, Description__c, Ingredients__c, Image1__c, Image2__c,
101
+ Veg_NonVeg__c, Section__c, Total_Ordered__c
 
102
  FROM Custom_Dish__c
103
  WHERE CreatedDate >= LAST_N_DAYS:7
104
  """
 
110
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
111
  item['Total_Ordered__c'] = 0
112
  item['Video1__c'] = get_valid_video_path(item['Name'])
113
+ # Set default values for Ingredients__c and Description__c if null
114
+ item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
115
+ item['Description__c'] = item.get('Description__c', 'No description available')
116
 
117
  # Merge both Menu_Item__c and Custom_Dish__c records
118
  all_items = food_items + custom_dishes
 
153
 
154
  except Exception as e:
155
  print(f"Error fetching menu data: {str(e)}")
156
+ # Fallback data with video support and Ingredients__c
157
  ordered_menu = {section: [] for section in SECTION_ORDER}
158
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
159
  ordered_menu["Best Sellers"] = [{
160
  "Name": name,
161
  "Price__c": "12.99",
162
  "Description__c": f"Popular {name}",
163
+ "Ingredients__c": "Not specified",
164
  "Image1__c": "/static/placeholder.jpg",
165
  "Video1__c": get_valid_video_path(name),
166
  "Total_Ordered__c": 100,
167
+ "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg"
 
 
 
168
  } for name in best_sellers]
169
 
170
  categories = ["All", "Veg", "Non veg"]
 
184
  cart_item_count=cart_item_count
185
  )
186
 
 
187
  @menu_blueprint.route('/api/addons', methods=['GET'])
188
  def get_addons():
189
  item_name = request.args.get('item_name')