Update menu.py
Browse files
menu.py
CHANGED
@@ -23,19 +23,14 @@ 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 |
-
# 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,10 +72,11 @@ def menu():
|
|
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
|
81 |
menu_query = """
|
82 |
SELECT Name, Price__c, Description__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,11 +87,16 @@ def menu():
|
|
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 |
|
95 |
-
# Query to fetch Custom_Dish__c records
|
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 |
FROM Custom_Dish__c
|
100 |
WHERE CreatedDate >= LAST_N_DAYS:7
|
101 |
"""
|
@@ -107,6 +108,9 @@ def menu():
|
|
107 |
if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
|
108 |
item['Total_Ordered__c'] = 0
|
109 |
item['Video1__c'] = get_valid_video_path(item['Name'])
|
|
|
|
|
|
|
110 |
|
111 |
# Merge both Menu_Item__c and Custom_Dish__c records
|
112 |
all_items = food_items + custom_dishes
|
@@ -147,7 +151,6 @@ def menu():
|
|
147 |
|
148 |
except Exception as e:
|
149 |
print(f"Error fetching menu data: {str(e)}")
|
150 |
-
# Fallback data with video support
|
151 |
ordered_menu = {section: [] for section in SECTION_ORDER}
|
152 |
best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
|
153 |
ordered_menu["Best Sellers"] = [{
|
@@ -157,7 +160,10 @@ def menu():
|
|
157 |
"Image1__c": "/static/placeholder.jpg",
|
158 |
"Video1__c": get_valid_video_path(name),
|
159 |
"Total_Ordered__c": 100,
|
160 |
-
"Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg"
|
|
|
|
|
|
|
161 |
} for name in best_sellers]
|
162 |
|
163 |
categories = ["All", "Veg", "Non veg"]
|
@@ -177,6 +183,7 @@ def menu():
|
|
177 |
cart_item_count=cart_item_count
|
178 |
)
|
179 |
|
|
|
180 |
@menu_blueprint.route('/api/addons', methods=['GET'])
|
181 |
def get_addons():
|
182 |
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 |
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 |
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 |
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 |
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 |
|
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"] = [{
|
|
|
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 |
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')
|