lokesh341 commited on
Commit
773dd33
·
verified ·
1 Parent(s): 4d0eb18

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +25 -22
menu.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
2
  from salesforce import get_salesforce_connection
3
  import os
@@ -23,14 +24,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,10 +78,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 Ingredients__c
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, Ingredients__c
79
  FROM Menu_Item__c
80
  """
81
  result = sf.query(menu_query)
@@ -86,14 +92,11 @@ def menu():
86
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
87
  item['Total_Ordered__c'] = 0
88
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
89
- # Ensure Ingredients__c and Description__c are present
90
- item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
91
- item['Description__c'] = item.get('Description__c', 'No description available')
92
 
93
  # Query to fetch Custom_Dish__c records
94
  custom_dish_query = """
95
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
96
- Veg_NonVeg__c, Section__c, Total_Ordered__c, Ingredients__c
97
  FROM Custom_Dish__c
98
  WHERE CreatedDate >= LAST_N_DAYS:7
99
  """
@@ -105,8 +108,6 @@ def menu():
105
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
106
  item['Total_Ordered__c'] = 0
107
  item['Video1__c'] = get_valid_video_path(item['Name'])
108
- item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
109
- item['Description__c'] = item.get('Description__c', 'No description available')
110
 
111
  # Merge both Menu_Item__c and Custom_Dish__c records
112
  all_items = food_items + custom_dishes
@@ -147,6 +148,7 @@ def menu():
147
 
148
  except Exception as e:
149
  print(f"Error fetching menu data: {str(e)}")
 
150
  ordered_menu = {section: [] for section in SECTION_ORDER}
151
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
152
  ordered_menu["Best Sellers"] = [{
@@ -156,8 +158,7 @@ def menu():
156
  "Image1__c": "/static/placeholder.jpg",
157
  "Video1__c": get_valid_video_path(name),
158
  "Total_Ordered__c": 100,
159
- "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg",
160
- "Ingredients__c": "Sample ingredients",
161
  } for name in best_sellers]
162
 
163
  categories = ["All", "Veg", "Non veg"]
@@ -308,7 +309,9 @@ def add_to_cart():
308
 
309
  except Exception as e:
310
  print(f"Error adding item to cart: {str(e)}")
311
- return jsonify({"success": False, "error": "An error occurred while adding the item to the cart."}), 500from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
 
 
312
  from salesforce import get_salesforce_connection
313
  import os
314
 
@@ -333,14 +336,19 @@ def get_valid_video_path(item_name, video_url=None):
333
  Get valid video path for item with placeholder fallback
334
  Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
335
  """
 
336
  if video_url:
 
337
  if video_url.startswith(('http://', 'https://')):
338
  return video_url
 
339
  elif video_url.startswith('/'):
340
  return video_url
 
341
  elif video_url.startswith('069'):
342
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
343
 
 
344
  if not os.path.exists(PLACEHOLDER_PATH):
345
  open(PLACEHOLDER_PATH, 'wb').close()
346
  print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
@@ -382,10 +390,10 @@ def menu():
382
  cart_count_result = sf.query(cart_query)
383
  cart_item_count = cart_count_result['totalSize']
384
 
385
- # Query to fetch Menu_Item__c records including Ingredients__c
386
  menu_query = """
387
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
388
- Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c, Ingredients__c
389
  FROM Menu_Item__c
390
  """
391
  result = sf.query(menu_query)
@@ -396,14 +404,11 @@ def menu():
396
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
397
  item['Total_Ordered__c'] = 0
398
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
399
- # Ensure Ingredients__c and Description__c are present
400
- item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
401
- item['Description__c'] = item.get('Description__c', 'No description available')
402
 
403
  # Query to fetch Custom_Dish__c records
404
  custom_dish_query = """
405
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
406
- Veg_NonVeg__c, Section__c, Total_Ordered__c, Ingredients__c
407
  FROM Custom_Dish__c
408
  WHERE CreatedDate >= LAST_N_DAYS:7
409
  """
@@ -415,8 +420,6 @@ def menu():
415
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
416
  item['Total_Ordered__c'] = 0
417
  item['Video1__c'] = get_valid_video_path(item['Name'])
418
- item['Ingredients__c'] = item.get('Ingredients__c', 'Not specified')
419
- item['Description__c'] = item.get('Description__c', 'No description available')
420
 
421
  # Merge both Menu_Item__c and Custom_Dish__c records
422
  all_items = food_items + custom_dishes
@@ -457,6 +460,7 @@ def menu():
457
 
458
  except Exception as e:
459
  print(f"Error fetching menu data: {str(e)}")
 
460
  ordered_menu = {section: [] for section in SECTION_ORDER}
461
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
462
  ordered_menu["Best Sellers"] = [{
@@ -466,8 +470,7 @@ def menu():
466
  "Image1__c": "/static/placeholder.jpg",
467
  "Video1__c": get_valid_video_path(name),
468
  "Total_Ordered__c": 100,
469
- "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg",
470
- "Ingredients__c": "Sample ingredients",
471
  } for name in best_sellers]
472
 
473
  categories = ["All", "Veg", "Non veg"]
@@ -618,4 +621,4 @@ def add_to_cart():
618
 
619
  except Exception as e:
620
  print(f"Error adding item to cart: {str(e)}")
621
- return jsonify({"success": False, "error": "An error occurred while adding the item to the cart."}), 500
 
1
+
2
  from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
3
  from salesforce import get_salesforce_connection
4
  import os
 
24
  Get valid video path for item with placeholder fallback
25
  Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
26
  """
27
+ # First try: Video1__c from Salesforce if provided
28
  if video_url:
29
+ # If it's a complete URL (http/https)
30
  if video_url.startswith(('http://', 'https://')):
31
  return video_url
32
+ # If it's a relative path (/videos/xxx.mp4)
33
  elif video_url.startswith('/'):
34
  return video_url
35
+ # If it's a Salesforce File ID (starts with '069')
36
  elif video_url.startswith('069'):
37
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
38
 
39
+ # Final fallback: placeholder.mp4
40
  if not os.path.exists(PLACEHOLDER_PATH):
41
  open(PLACEHOLDER_PATH, 'wb').close()
42
  print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
 
78
  cart_count_result = sf.query(cart_query)
79
  cart_item_count = cart_count_result['totalSize']
80
 
81
+ # Query to fetch Menu_Item__c records including Video1__c
82
  menu_query = """
83
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
84
+ Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c
85
  FROM Menu_Item__c
86
  """
87
  result = sf.query(menu_query)
 
92
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
93
  item['Total_Ordered__c'] = 0
94
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
 
 
 
95
 
96
  # Query to fetch Custom_Dish__c records
97
  custom_dish_query = """
98
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
99
+ Veg_NonVeg__c, Section__c, Total_Ordered__c
100
  FROM Custom_Dish__c
101
  WHERE CreatedDate >= LAST_N_DAYS:7
102
  """
 
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
 
112
  # Merge both Menu_Item__c and Custom_Dish__c records
113
  all_items = food_items + custom_dishes
 
148
 
149
  except Exception as e:
150
  print(f"Error fetching menu data: {str(e)}")
151
+ # Fallback data with video support
152
  ordered_menu = {section: [] for section in SECTION_ORDER}
153
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
154
  ordered_menu["Best Sellers"] = [{
 
158
  "Image1__c": "/static/placeholder.jpg",
159
  "Video1__c": get_valid_video_path(name),
160
  "Total_Ordered__c": 100,
161
+ "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg"
 
162
  } for name in best_sellers]
163
 
164
  categories = ["All", "Veg", "Non veg"]
 
309
 
310
  except Exception as e:
311
  print(f"Error adding item to cart: {str(e)}")
312
+ return jsonify({"success": False, "error": "An error occurred while adding the item to the cart."}), 500
313
+
314
+ from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
315
  from salesforce import get_salesforce_connection
316
  import os
317
 
 
336
  Get valid video path for item with placeholder fallback
337
  Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
338
  """
339
+ # First try: Video1__c from Salesforce if provided
340
  if video_url:
341
+ # If it's a complete URL (http/https)
342
  if video_url.startswith(('http://', 'https://')):
343
  return video_url
344
+ # If it's a relative path (/videos/xxx.mp4)
345
  elif video_url.startswith('/'):
346
  return video_url
347
+ # If it's a Salesforce File ID (starts with '069')
348
  elif video_url.startswith('069'):
349
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
350
 
351
+ # Final fallback: placeholder.mp4
352
  if not os.path.exists(PLACEHOLDER_PATH):
353
  open(PLACEHOLDER_PATH, 'wb').close()
354
  print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
 
390
  cart_count_result = sf.query(cart_query)
391
  cart_item_count = cart_count_result['totalSize']
392
 
393
+ # Query to fetch Menu_Item__c records including Video1__c
394
  menu_query = """
395
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
396
+ Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c
397
  FROM Menu_Item__c
398
  """
399
  result = sf.query(menu_query)
 
404
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
405
  item['Total_Ordered__c'] = 0
406
  item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
 
 
 
407
 
408
  # Query to fetch Custom_Dish__c records
409
  custom_dish_query = """
410
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
411
+ Veg_NonVeg__c, Section__c, Total_Ordered__c
412
  FROM Custom_Dish__c
413
  WHERE CreatedDate >= LAST_N_DAYS:7
414
  """
 
420
  if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
421
  item['Total_Ordered__c'] = 0
422
  item['Video1__c'] = get_valid_video_path(item['Name'])
 
 
423
 
424
  # Merge both Menu_Item__c and Custom_Dish__c records
425
  all_items = food_items + custom_dishes
 
460
 
461
  except Exception as e:
462
  print(f"Error fetching menu data: {str(e)}")
463
+ # Fallback data with video support
464
  ordered_menu = {section: [] for section in SECTION_ORDER}
465
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
466
  ordered_menu["Best Sellers"] = [{
 
470
  "Image1__c": "/static/placeholder.jpg",
471
  "Video1__c": get_valid_video_path(name),
472
  "Total_Ordered__c": 100,
473
+ "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg"
 
474
  } for name in best_sellers]
475
 
476
  categories = ["All", "Veg", "Non veg"]
 
621
 
622
  except Exception as e:
623
  print(f"Error adding item to cart: {str(e)}")
624
+ return jsonify({"success": False, "error": "An error occurred while adding the item to the cart."}), 500