Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, render_template,
|
2 |
from simple_salesforce import Salesforce
|
3 |
from dotenv import load_dotenv
|
4 |
import os
|
@@ -22,17 +22,13 @@ def get_salesforce_connection():
|
|
22 |
print(f"Error connecting to Salesforce: {e}")
|
23 |
return None
|
24 |
|
25 |
-
# Initialize Salesforce connection
|
26 |
sf = get_salesforce_connection()
|
27 |
|
28 |
@app.route('/')
|
29 |
def index():
|
30 |
return render_template('index.html')
|
31 |
|
32 |
-
@app.route('/static/<path:filename>')
|
33 |
-
def serve_static(filename):
|
34 |
-
return send_from_directory('static', filename)
|
35 |
-
|
36 |
@app.route('/get_ingredients', methods=['POST'])
|
37 |
def get_ingredients():
|
38 |
global sf
|
@@ -43,15 +39,15 @@ def get_ingredients():
|
|
43 |
|
44 |
dietary_preference = request.json.get('dietary_preference', '').lower()
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
soql = "SELECT Name, Image_URL__c FROM Sector_Detail__c LIMIT 200"
|
53 |
|
54 |
try:
|
|
|
55 |
result = sf.query(soql)
|
56 |
ingredients = [
|
57 |
{"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
from simple_salesforce import Salesforce
|
3 |
from dotenv import load_dotenv
|
4 |
import os
|
|
|
22 |
print(f"Error connecting to Salesforce: {e}")
|
23 |
return None
|
24 |
|
25 |
+
# Initialize Salesforce connection (can be moved to request scope in production)
|
26 |
sf = get_salesforce_connection()
|
27 |
|
28 |
@app.route('/')
|
29 |
def index():
|
30 |
return render_template('index.html')
|
31 |
|
|
|
|
|
|
|
|
|
32 |
@app.route('/get_ingredients', methods=['POST'])
|
33 |
def get_ingredients():
|
34 |
global sf
|
|
|
39 |
|
40 |
dietary_preference = request.json.get('dietary_preference', '').lower()
|
41 |
|
42 |
+
# Validate and map dietary preference to SOQL condition
|
43 |
+
preference_map = {
|
44 |
+
'vegetarian': "Category__c = 'Veg'",
|
45 |
+
'non-vegetarian': "Category__c = 'Non-Veg'"
|
46 |
+
}
|
47 |
+
condition = preference_map.get(dietary_preference, "1=1") # Default to all if invalid
|
|
|
48 |
|
49 |
try:
|
50 |
+
soql = f"SELECT Name, Image_URL__c FROM Sector_Detail__c WHERE {condition} LIMIT 200"
|
51 |
result = sf.query(soql)
|
52 |
ingredients = [
|
53 |
{"name": record['Name'], "image_url": record.get('Image_URL__c', '')}
|