Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,51 @@ import re
|
|
| 3 |
from reportlab.lib.pagesizes import letter
|
| 4 |
from reportlab.pdfgen import canvas
|
| 5 |
import bleach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Clean input to prevent injection attacks
|
| 8 |
def sanitize_input(text):
|
|
@@ -10,7 +55,7 @@ def sanitize_input(text):
|
|
| 10 |
return ""
|
| 11 |
return bleach.clean(text.strip())
|
| 12 |
|
| 13 |
-
#
|
| 14 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 15 |
score = 0 # Base score set to 0 for clearer range
|
| 16 |
missing_items = []
|
|
@@ -56,13 +101,13 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 56 |
checklist_summary = "\n".join(checklist_details)
|
| 57 |
missing_summary = "None" if not missing_items else ", ".join(missing_items)
|
| 58 |
|
| 59 |
-
# Generate progress bar HTML
|
| 60 |
color = "red" if score < 70 else "yellow" if score < 90 else "green"
|
| 61 |
progress_bar = f'<progress value="{score}" max="100" style="width:100%;height:20px;background-color:{color}">{score}%</progress>'
|
| 62 |
|
| 63 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 64 |
|
| 65 |
-
# Generate PDF report
|
| 66 |
def generate_pdf(score, checklist_summary, missing_summary, status):
|
| 67 |
pdf_file = "readiness_report.pdf"
|
| 68 |
c = canvas.Canvas(pdf_file, pagesize=letter)
|
|
|
|
| 3 |
from reportlab.lib.pagesizes import letter
|
| 4 |
from reportlab.pdfgen import canvas
|
| 5 |
import bleach
|
| 6 |
+
from simple_salesforce import Salesforce, SalesforceError
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Salesforce configuration (loaded from environment variables for potential future use)
|
| 10 |
+
SF_USERNAME = os.getenv("SF_USERNAME")
|
| 11 |
+
SF_PASSWORD = os.getenv("SF_PASSWORD")
|
| 12 |
+
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
|
| 13 |
+
SF_INSTANCE_URL = os.getenv("SF_INSTANCE_URL")
|
| 14 |
+
|
| 15 |
+
# Initialize Salesforce connection (for potential future use)
|
| 16 |
+
def init_salesforce():
|
| 17 |
+
try:
|
| 18 |
+
sf = Salesforce(
|
| 19 |
+
username=SF_USERNAME,
|
| 20 |
+
password=SF_PASSWORD,
|
| 21 |
+
security_token=SF_SECURITY_TOKEN,
|
| 22 |
+
instance_url=SF_INSTANCE_URL
|
| 23 |
+
)
|
| 24 |
+
return sf, "Salesforce connected successfully"
|
| 25 |
+
except SalesforceError as e:
|
| 26 |
+
return None, f"Salesforce connection failed: {str(e)}"
|
| 27 |
+
|
| 28 |
+
# Create Salesforce record (for potential future use)
|
| 29 |
+
def create_salesforce_record(score, checklist_summary, missing_summary, status):
|
| 30 |
+
sf, connection_message = init_salesforce()
|
| 31 |
+
if not sf:
|
| 32 |
+
return connection_message
|
| 33 |
+
|
| 34 |
+
# Map app status to Salesforce Case.Status values
|
| 35 |
+
sf_status = "New" # Default for Pending and Escalated
|
| 36 |
+
if status == "Completed":
|
| 37 |
+
sf_status = "Closed"
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
record = {
|
| 41 |
+
"Subject": "Project Readiness Evaluation",
|
| 42 |
+
"Description": f"Readiness Score: {score}%\nChecklist Summary:\n{checklist_summary}\nMissing Items: {missing_summary}",
|
| 43 |
+
"Status": sf_status,
|
| 44 |
+
"Origin": "Web",
|
| 45 |
+
"Priority": "Medium"
|
| 46 |
+
}
|
| 47 |
+
result = sf.Case.create(record)
|
| 48 |
+
return f"Case record created successfully in Salesforce. Case ID: {result['id']}"
|
| 49 |
+
except SalesforceError as e:
|
| 50 |
+
return f"Failed to create Salesforce Case record: {str(e)}"
|
| 51 |
|
| 52 |
# Clean input to prevent injection attacks
|
| 53 |
def sanitize_input(text):
|
|
|
|
| 55 |
return ""
|
| 56 |
return bleach.clean(text.strip())
|
| 57 |
|
| 58 |
+
# Rule-based completeness engine to evaluate readiness
|
| 59 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 60 |
score = 0 # Base score set to 0 for clearer range
|
| 61 |
missing_items = []
|
|
|
|
| 101 |
checklist_summary = "\n".join(checklist_details)
|
| 102 |
missing_summary = "None" if not missing_items else ", ".join(missing_items)
|
| 103 |
|
| 104 |
+
# Generate progress bar HTML (alert indicator)
|
| 105 |
color = "red" if score < 70 else "yellow" if score < 90 else "green"
|
| 106 |
progress_bar = f'<progress value="{score}" max="100" style="width:100%;height:20px;background-color:{color}">{score}%</progress>'
|
| 107 |
|
| 108 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 109 |
|
| 110 |
+
# Generate PDF report with signature slots
|
| 111 |
def generate_pdf(score, checklist_summary, missing_summary, status):
|
| 112 |
pdf_file = "readiness_report.pdf"
|
| 113 |
c = canvas.Canvas(pdf_file, pagesize=letter)
|