nagasurendra commited on
Commit
22a8ef5
·
verified ·
1 Parent(s): 368bf06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -258,6 +258,8 @@ def customer_details():
258
  print(f"Error fetching customer details: {str(e)}")
259
  return jsonify({"success": False, "message": f"Error fetching customer details: {str(e)}"})
260
 
 
 
261
  @app.route("/order-history", methods=["GET"])
262
  def order_history():
263
  email = session.get('user_email') # Get logged-in user's email
@@ -276,23 +278,35 @@ def order_history():
276
 
277
  orders = result.get("records", []) # Fetch all orders
278
 
279
- # Strip image URLs from order details and split remaining data by new lines
280
  for order in orders:
281
  order_details = order.get("Order_Details__c", "")
282
- # Remove image URLs using regex
283
- cleaned_details = re.sub(r'http[s]?://\S+', '', order_details)
284
-
285
- # Now split the cleaned details by lines and join them with <br> to create line breaks
286
- cleaned_details = cleaned_details.replace("\n", " ")
287
-
288
- # Update the order details with the cleaned and formatted details
289
- order['Order_Details__c'] = cleaned_details
 
 
 
 
 
 
 
 
 
 
 
290
 
291
  return render_template("order_history.html", orders=orders)
292
 
293
  except Exception as e:
294
  print(f"Error fetching order history: {str(e)}")
295
  return render_template("order_history.html", orders=[], error=str(e))
 
296
  app.permanent_session_lifetime = timedelta(minutes=5)
297
  @app.before_request
298
  def check_session_timeout():
 
258
  print(f"Error fetching customer details: {str(e)}")
259
  return jsonify({"success": False, "message": f"Error fetching customer details: {str(e)}"})
260
 
261
+
262
+
263
  @app.route("/order-history", methods=["GET"])
264
  def order_history():
265
  email = session.get('user_email') # Get logged-in user's email
 
278
 
279
  orders = result.get("records", []) # Fetch all orders
280
 
281
+ # Format the order details for better readability
282
  for order in orders:
283
  order_details = order.get("Order_Details__c", "")
284
+ items = order_details.split("\n") # Assuming each item is separated by a new line
285
+ formatted_items = []
286
+
287
+ # Loop through the items and format them as "item name * quantity"
288
+ for item in items:
289
+ item_details = item.split(" | ")
290
+ if len(item_details) > 1:
291
+ name = item_details[0].strip()
292
+ quantity = item_details[1].strip()
293
+ formatted_items.append(f"{name} * {quantity}")
294
+
295
+ # Join the formatted items into a single string
296
+ order['formatted_items'] = ", ".join(formatted_items)
297
+
298
+ # Get the order date and time from CreatedDate
299
+ created_date = order.get("CreatedDate", "")
300
+ if created_date:
301
+ # Format the date and time (e.g., "February 27, 7:40 PM")
302
+ order['formatted_date'] = created_date.strftime('%B %d, %I:%M %p')
303
 
304
  return render_template("order_history.html", orders=orders)
305
 
306
  except Exception as e:
307
  print(f"Error fetching order history: {str(e)}")
308
  return render_template("order_history.html", orders=[], error=str(e))
309
+
310
  app.permanent_session_lifetime = timedelta(minutes=5)
311
  @app.before_request
312
  def check_session_timeout():