Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -497,8 +497,6 @@ def menu(): | |
| 497 | 
             
                    result = sf.query(menu_query)
         | 
| 498 | 
             
                    food_items = result['records'] if 'records' in result else []
         | 
| 499 |  | 
| 500 | 
            -
                    print(f"Fetched menu items: {len(food_items)} items")  # Debugging
         | 
| 501 | 
            -
             | 
| 502 | 
             
                    # Ensure Total_Ordered__c has a valid value
         | 
| 503 | 
             
                    for item in food_items:
         | 
| 504 | 
             
                        if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
         | 
| @@ -508,7 +506,7 @@ def menu(): | |
| 508 | 
             
                    custom_dish_query = """
         | 
| 509 | 
             
                        SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c 
         | 
| 510 | 
             
                        FROM Custom_Dish__c
         | 
| 511 | 
            -
                        WHERE CreatedDate >= LAST_N_DAYS:7 
         | 
| 512 | 
             
                    """
         | 
| 513 | 
             
                    custom_dish_result = sf.query(custom_dish_query)
         | 
| 514 | 
             
                    custom_dishes = custom_dish_result['records'] if 'records' in custom_dish_result else []
         | 
| @@ -522,7 +520,6 @@ def menu(): | |
| 522 |  | 
| 523 | 
             
                    # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
         | 
| 524 | 
             
                    best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
         | 
| 525 | 
            -
                    print(f"Best sellers: {[item['Name'] for item in best_sellers]}")  # Debugging
         | 
| 526 |  | 
| 527 | 
             
                    if selected_category == "Veg":
         | 
| 528 | 
             
                        best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
         | 
| @@ -536,12 +533,19 @@ def menu(): | |
| 536 | 
             
                    if best_sellers:
         | 
| 537 | 
             
                        ordered_menu["Best Sellers"] = best_sellers
         | 
| 538 |  | 
|  | |
|  | |
|  | |
| 539 | 
             
                    # Filter and organize menu items based on category and section (to avoid duplicates)
         | 
| 540 | 
             
                    for item in all_items:
         | 
| 541 | 
             
                        section = item.get("Section__c", "Others")  # Default to "Others" if missing
         | 
| 542 | 
             
                        if section not in ordered_menu:
         | 
| 543 | 
             
                            ordered_menu[section] = []
         | 
| 544 |  | 
|  | |
|  | |
|  | |
|  | |
| 545 | 
             
                        # Apply category filters
         | 
| 546 | 
             
                        if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
         | 
| 547 | 
             
                            continue
         | 
| @@ -549,6 +553,7 @@ def menu(): | |
| 549 | 
             
                            continue
         | 
| 550 |  | 
| 551 | 
             
                        ordered_menu[section].append(item)
         | 
|  | |
| 552 | 
             
                        print(f"Added item to {section}: {item['Name']}")  # Debugging
         | 
| 553 |  | 
| 554 | 
             
                    # Remove empty sections
         | 
| @@ -576,6 +581,7 @@ def menu(): | |
| 576 | 
             
                    first_letter=first_letter  # Pass first letter to the template
         | 
| 577 | 
             
                )
         | 
| 578 |  | 
|  | |
| 579 | 
             
            @app.route("/cart", methods=["GET"])
         | 
| 580 | 
             
            def cart():
         | 
| 581 | 
             
                email = session.get('user_email')
         | 
|  | |
| 497 | 
             
                    result = sf.query(menu_query)
         | 
| 498 | 
             
                    food_items = result['records'] if 'records' in result else []
         | 
| 499 |  | 
|  | |
|  | |
| 500 | 
             
                    # Ensure Total_Ordered__c has a valid value
         | 
| 501 | 
             
                    for item in food_items:
         | 
| 502 | 
             
                        if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
         | 
|  | |
| 506 | 
             
                    custom_dish_query = """
         | 
| 507 | 
             
                        SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c 
         | 
| 508 | 
             
                        FROM Custom_Dish__c
         | 
| 509 | 
            +
                        WHERE CreatedDate >= LAST_N_DAYS:7 AND Total_Ordered__c > 10
         | 
| 510 | 
             
                    """
         | 
| 511 | 
             
                    custom_dish_result = sf.query(custom_dish_query)
         | 
| 512 | 
             
                    custom_dishes = custom_dish_result['records'] if 'records' in custom_dish_result else []
         | 
|  | |
| 520 |  | 
| 521 | 
             
                    # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
         | 
| 522 | 
             
                    best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
         | 
|  | |
| 523 |  | 
| 524 | 
             
                    if selected_category == "Veg":
         | 
| 525 | 
             
                        best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
         | 
|  | |
| 533 | 
             
                    if best_sellers:
         | 
| 534 | 
             
                        ordered_menu["Best Sellers"] = best_sellers
         | 
| 535 |  | 
| 536 | 
            +
                    # Create a set to track item names already added to prevent duplicates
         | 
| 537 | 
            +
                    added_item_names = set()
         | 
| 538 | 
            +
             | 
| 539 | 
             
                    # Filter and organize menu items based on category and section (to avoid duplicates)
         | 
| 540 | 
             
                    for item in all_items:
         | 
| 541 | 
             
                        section = item.get("Section__c", "Others")  # Default to "Others" if missing
         | 
| 542 | 
             
                        if section not in ordered_menu:
         | 
| 543 | 
             
                            ordered_menu[section] = []
         | 
| 544 |  | 
| 545 | 
            +
                        # Skip item if it's already been added to avoid duplicates
         | 
| 546 | 
            +
                        if item['Name'] in added_item_names:
         | 
| 547 | 
            +
                            continue
         | 
| 548 | 
            +
             | 
| 549 | 
             
                        # Apply category filters
         | 
| 550 | 
             
                        if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
         | 
| 551 | 
             
                            continue
         | 
|  | |
| 553 | 
             
                            continue
         | 
| 554 |  | 
| 555 | 
             
                        ordered_menu[section].append(item)
         | 
| 556 | 
            +
                        added_item_names.add(item['Name'])  # Add item to the set of added items
         | 
| 557 | 
             
                        print(f"Added item to {section}: {item['Name']}")  # Debugging
         | 
| 558 |  | 
| 559 | 
             
                    # Remove empty sections
         | 
|  | |
| 581 | 
             
                    first_letter=first_letter  # Pass first letter to the template
         | 
| 582 | 
             
                )
         | 
| 583 |  | 
| 584 | 
            +
             | 
| 585 | 
             
            @app.route("/cart", methods=["GET"])
         | 
| 586 | 
             
            def cart():
         | 
| 587 | 
             
                email = session.get('user_email')
         |