lokesh341 commited on
Commit
dd99f96
·
verified ·
1 Parent(s): 2606639

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -6,6 +6,7 @@ import base64
6
  import os
7
  import logging
8
  import traceback
 
9
  from datetime import datetime
10
  from fastapi.responses import HTMLResponse
11
  from simple_salesforce import Salesforce
@@ -238,7 +239,7 @@ async def get_dashboard():
238
  <head>
239
  <title>Subcontractor Performance Score App</title>
240
  <style>
241
- body { font-family: "Arial", sans-serif; margin: 20px; background-color: #f5f7fa; }
242
  h1, h2 { color: #333; }
243
  .container { max-width: 1200px; margin: 0 auto; }
244
  .summary-cards { display: flex; gap: 20px; margin-bottom: 20px; }
@@ -311,10 +312,12 @@ async def get_dashboard():
311
  trend = "trend-up" if scores['finalScore'] >= 90 else "trend-down" if scores['finalScore'] < 70 else "trend-flat"
312
  status_class = "status-good" if not alert_flag else "status-alert"
313
  status_text = "Good" if not alert_flag else "Alert"
 
 
314
  html_content += f"""
315
  <tr>
316
  <td>#{idx}</td>
317
- <td>{log['vendorLogName']}</td>
318
  <td>{scores['finalScore']}</td>
319
  <td class="{trend}">{"↗" if trend == "trend-up" else "↘" if trend == "trend-down" else "—"}</td>
320
  <td><span class="{status_class}">{status_text}</span></td>
@@ -334,9 +337,10 @@ async def get_dashboard():
334
  if alert_logs:
335
  for log in alert_logs[:3]: # Show up to 3 alerts
336
  scores = log['scores']
 
337
  html_content += f"""
338
  <div style="margin-bottom: 10px;">
339
- <span style="color: #ef6c00;">⚠️ {log['vendorLogName']}</span> - Overall: {scores['finalScore']}
340
  <br>Quality: {scores['qualityScore']} | Timeliness: {scores['timelinessScore']}
341
  <a href="#" style="margin-left: 10px; color: #1976d2;">Review</a>
342
  </div>
@@ -356,9 +360,10 @@ async def get_dashboard():
356
 
357
  for log in top_performing_logs:
358
  scores = log['scores']
 
359
  html_content += f"""
360
  <div style="flex: 1; min-width: 200px;">
361
- <p>{log['vendorLogName']}<br><small>Last updated: 5/1/2025</small></p>
362
  <span class="score-circle" style="background: #e0e0e0;">{scores['finalScore']}</span> Overall
363
  <span class="score-circle" style="background: #e0e0e0;">{scores['qualityScore']}</span> Quality
364
  <span class="score-circle" style="background: #e0e0e0;">{scores['timelinessScore']}</span> Time
@@ -385,8 +390,9 @@ async def get_dashboard():
385
  """
386
 
387
  for log in vendor_logs:
 
388
  html_content += f"""
389
- <option>{log['vendorLogName']}</option>
390
  """
391
 
392
  html_content += """
@@ -412,9 +418,10 @@ async def get_dashboard():
412
  """
413
 
414
  for log in sorted_logs[:5]: # Show recent 5 reports
 
415
  html_content += f"""
416
  <div style="margin-bottom: 10px;">
417
- 📄 {log['vendorLogName']} - Monthly Performance
418
  <span style="float: right;">
419
  <small>5/1/2025</small>
420
  <a href="#" style="margin-left: 10px;">⬇</a>
@@ -433,7 +440,8 @@ async def get_dashboard():
433
  </body>
434
  </html>
435
  """
436
- return HTMLResponse(content=html_content)
 
437
  except Exception as e:
438
  # Log the full stack trace for better debugging
439
  error_trace = traceback.format_exc()
 
6
  import os
7
  import logging
8
  import traceback
9
+ import html # For escaping special characters
10
  from datetime import datetime
11
  from fastapi.responses import HTMLResponse
12
  from simple_salesforce import Salesforce
 
239
  <head>
240
  <title>Subcontractor Performance Score App</title>
241
  <style>
242
+ body { font-family: Arial, sans-serif; margin: 20px; background-color: #f5f7fa; }
243
  h1, h2 { color: #333; }
244
  .container { max-width: 1200px; margin: 0 auto; }
245
  .summary-cards { display: flex; gap: 20px; margin-bottom: 20px; }
 
312
  trend = "trend-up" if scores['finalScore'] >= 90 else "trend-down" if scores['finalScore'] < 70 else "trend-flat"
313
  status_class = "status-good" if not alert_flag else "status-alert"
314
  status_text = "Good" if not alert_flag else "Alert"
315
+ # Escape dynamic data to prevent HTML injection
316
+ vendor_name = html.escape(log['vendorLogName'])
317
  html_content += f"""
318
  <tr>
319
  <td>#{idx}</td>
320
+ <td>{vendor_name}</td>
321
  <td>{scores['finalScore']}</td>
322
  <td class="{trend}">{"↗" if trend == "trend-up" else "↘" if trend == "trend-down" else "—"}</td>
323
  <td><span class="{status_class}">{status_text}</span></td>
 
337
  if alert_logs:
338
  for log in alert_logs[:3]: # Show up to 3 alerts
339
  scores = log['scores']
340
+ vendor_name = html.escape(log['vendorLogName'])
341
  html_content += f"""
342
  <div style="margin-bottom: 10px;">
343
+ <span style="color: #ef6c00;">⚠️ {vendor_name}</span> - Overall: {scores['finalScore']}
344
  <br>Quality: {scores['qualityScore']} | Timeliness: {scores['timelinessScore']}
345
  <a href="#" style="margin-left: 10px; color: #1976d2;">Review</a>
346
  </div>
 
360
 
361
  for log in top_performing_logs:
362
  scores = log['scores']
363
+ vendor_name = html.escape(log['vendorLogName'])
364
  html_content += f"""
365
  <div style="flex: 1; min-width: 200px;">
366
+ <p>{vendor_name}<br><small>Last updated: 5/1/2025</small></p>
367
  <span class="score-circle" style="background: #e0e0e0;">{scores['finalScore']}</span> Overall
368
  <span class="score-circle" style="background: #e0e0e0;">{scores['qualityScore']}</span> Quality
369
  <span class="score-circle" style="background: #e0e0e0;">{scores['timelinessScore']}</span> Time
 
390
  """
391
 
392
  for log in vendor_logs:
393
+ vendor_name = html.escape(log['vendorLogName'])
394
  html_content += f"""
395
+ <option>{vendor_name}</option>
396
  """
397
 
398
  html_content += """
 
418
  """
419
 
420
  for log in sorted_logs[:5]: # Show recent 5 reports
421
+ vendor_name = html.escape(log['vendorLogName'])
422
  html_content += f"""
423
  <div style="margin-bottom: 10px;">
424
+ 📄 {vendor_name} - Monthly Performance
425
  <span style="float: right;">
426
  <small>5/1/2025</small>
427
  <a href="#" style="margin-left: 10px;">⬇</a>
 
440
  </body>
441
  </html>
442
  """
443
+ # Ensure the HTML content is properly encoded
444
+ return HTMLResponse(content=html_content.encode('utf-8'), media_type="text/html; charset=utf-8")
445
  except Exception as e:
446
  # Log the full stack trace for better debugging
447
  error_trace = traceback.format_exc()