nagasurendra commited on
Commit
b20f786
·
verified ·
1 Parent(s): 9a673e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -82
app.py CHANGED
@@ -119,80 +119,8 @@ def login():
119
 
120
  return render_template("login.html")
121
 
122
- @app.route('/reward_status')
123
- def reward_status():
124
- # Get the user email from session (assuming the session is already set during checkout)
125
- email = session.get('user_email')
126
-
127
- if not email:
128
- return "User not logged in", 400
129
-
130
- # Query Salesforce to fetch the user's reward points
131
- try:
132
- # Query the Customer_Login__c object based on the user's email
133
- query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}'"
134
- user_data = sf.query(query)
135
-
136
- # Check if the user record was found
137
- if not user_data.get("records"):
138
- return "User not found", 400
139
-
140
- # Get the user's reward points from Salesforce
141
- user_points = user_data["records"][0].get("Reward_Points__c", 0)
142
-
143
- except Exception as e:
144
- return f"Error querying Salesforce: {str(e)}", 500
145
-
146
- # Define point ranges for each tier
147
- tiers = {
148
- "Bronze": 100, # Example: 0 to 100 for Bronze
149
- "Silver": 200, # Example: 100 to 200 for Silver
150
- "Gold": 300, # Example: 200 to 300 for Gold
151
- "Platinum": 500
152
- }
153
-
154
- # Logic for calculating the next tier's range and current progress
155
- current_tier = "Silver" # Example, dynamically determine this
156
-
157
- # Calculate the range for the current tier
158
- if current_tier == "Silver":
159
- start_point = 100 # Silver starts at 100
160
- end_point = 200 # Silver ends at 200
161
- elif current_tier == "Gold":
162
- start_point = 200 # Gold starts at 200
163
- end_point = 300 # Gold ends at 300
164
- else:
165
- start_point = 0 # Default start point for other tiers
166
- end_point = 100 # Default end point for other tiers
167
-
168
- # Calculate progress as a percentage
169
- if user_points >= start_point:
170
- progress_percentage = ((user_points - start_point) / (end_point - start_point)) * 100
171
- else:
172
- progress_percentage = 0
173
-
174
- # Calculate points to next tier
175
- points_needed_for_next_tier = end_point - user_points
176
- next_tier = "Gold" # Next tier name (you can dynamically calculate this)
177
- # Round the points before passing to the template
178
- user_points = round(user_points)
179
- points_needed_for_next_tier = round(points_needed_for_next_tier)
180
-
181
- # Pass these values to your template
182
- return render_template(
183
- 'reward_status.html',
184
- user_points=user_points,
185
- current_tier=current_tier,
186
- progress_percentage=progress_percentage,
187
- points_needed_for_next_tier=points_needed_for_next_tier,
188
- start_point=start_point,
189
- end_point=end_point,
190
- next_tier=next_tier,
191
- tiers=tiers
192
- )
193
  @app.route('/order_summary')
194
  def order_summary():
195
- # Get the user email from session (assuming the session is already set during checkout)
196
  email = session.get('user_email')
197
 
198
  if not email:
@@ -202,7 +130,6 @@ def order_summary():
202
  try:
203
  print(f"Fetching order details for email: {email}")
204
 
205
- # Query the Order__c object based on the user's email
206
  query = f"""
207
  SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
208
  FROM Order__c
@@ -212,8 +139,6 @@ def order_summary():
212
  """
213
  result = sf.query(query)
214
 
215
- print("Salesforce query result:", result)
216
-
217
  if not result.get("records"):
218
  print("No order found for this user.")
219
  return "No order found for this user", 400
@@ -252,14 +177,14 @@ def order_summary():
252
  {
253
  "name": menu_item['Ingredient_1__r']['Ingredient_Name__c'] if 'Ingredient_1__r' in menu_item else None,
254
  "image": menu_item['Ingredient_1__r']['Ingredient_Image__c'] if 'Ingredient_1__r' in menu_item else None,
255
- "health_benefits": menu_item['Ingredient_1__r']['Health_Benefits__c'] if 'Ingredient_1__r' in menu_item else None,
256
- "fun_facts": menu_item['Ingredient_1__r']['Fun_Facts__c'] if 'Ingredient_1__r' in menu_item else None
257
  },
258
  {
259
  "name": menu_item['Ingredient_2__r']['Ingredient_Name__c'] if 'Ingredient_2__r' in menu_item else None,
260
  "image": menu_item['Ingredient_2__r']['Ingredient_Image__c'] if 'Ingredient_2__r' in menu_item else None,
261
- "health_benefits": menu_item['Ingredient_2__r']['Health_Benefits__c'] if 'Ingredient_2__r' in menu_item else None,
262
- "fun_facts": menu_item['Ingredient_2__r']['Fun_Facts__c'] if 'Ingredient_2__r' in menu_item else None
263
  }
264
  ]
265
  })
@@ -272,7 +197,6 @@ def order_summary():
272
  else:
273
  print(f"Total items extracted: {len(order_items)}")
274
 
275
- # Now pass the necessary data to reward_status.html
276
  return render_template(
277
  'reward_status.html',
278
  order=order,
@@ -283,8 +207,6 @@ def order_summary():
283
  print(f"Error querying Salesforce: {str(e)}")
284
  return f"Error querying Salesforce: {str(e)}", 500
285
 
286
-
287
-
288
 
289
 
290
  @app.route("/logout")
 
119
 
120
  return render_template("login.html")
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  @app.route('/order_summary')
123
  def order_summary():
 
124
  email = session.get('user_email')
125
 
126
  if not email:
 
130
  try:
131
  print(f"Fetching order details for email: {email}")
132
 
 
133
  query = f"""
134
  SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
135
  FROM Order__c
 
139
  """
140
  result = sf.query(query)
141
 
 
 
142
  if not result.get("records"):
143
  print("No order found for this user.")
144
  return "No order found for this user", 400
 
177
  {
178
  "name": menu_item['Ingredient_1__r']['Ingredient_Name__c'] if 'Ingredient_1__r' in menu_item else None,
179
  "image": menu_item['Ingredient_1__r']['Ingredient_Image__c'] if 'Ingredient_1__r' in menu_item else None,
180
+ "health_benefits": menu_item['Ingredient_1__r']['Health_Benefits__c'] if 'Ingredient_1__r' in menu_item else 'No health benefits available',
181
+ "fun_facts": menu_item['Ingredient_1__r']['Fun_Facts__c'] if 'Ingredient_1__r' in menu_item else 'No fun facts available'
182
  },
183
  {
184
  "name": menu_item['Ingredient_2__r']['Ingredient_Name__c'] if 'Ingredient_2__r' in menu_item else None,
185
  "image": menu_item['Ingredient_2__r']['Ingredient_Image__c'] if 'Ingredient_2__r' in menu_item else None,
186
+ "health_benefits": menu_item['Ingredient_2__r']['Health_Benefits__c'] if 'Ingredient_2__r' in menu_item else 'No health benefits available',
187
+ "fun_facts": menu_item['Ingredient_2__r']['Fun_Facts__c'] if 'Ingredient_2__r' in menu_item else 'No fun facts available'
188
  }
189
  ]
190
  })
 
197
  else:
198
  print(f"Total items extracted: {len(order_items)}")
199
 
 
200
  return render_template(
201
  'reward_status.html',
202
  order=order,
 
207
  print(f"Error querying Salesforce: {str(e)}")
208
  return f"Error querying Salesforce: {str(e)}", 500
209
 
 
 
210
 
211
 
212
  @app.route("/logout")