#!/usr/bin/env python3 """Render the internal ops dashboard (static HTML) from queue.json. Deployed to an unlisted path on the Pages project. Internal only: shows costs/margins (never customer-facing). Customers have no access. """ import os, json, datetime, html as htmllib BASE = os.path.dirname(os.path.abspath(__file__)) QUEUE = os.path.join(BASE, "dashboard", "queue.json") STATUS_STYLE = { "draft_ready": ("background:#d4edda;color:#155724", "Draft ready for Sean"), "engaged": ("background:#cce5ff;color:#004085", "Customer engaged"), "needs_review": ("background:#fff3cd;color:#856404", "Needs review"), "draft_failed": ("background:#f8d7da;color:#721c24", "Draft failed"), } def render(): queue = json.load(open(QUEUE)) if os.path.exists(QUEUE) else [] cards = [] for q in queue: c = q.get("customer", {}) status = q.get("status", "?") style, label = STATUS_STYLE.get( status, STATUS_STYLE.get(q.get("draft_status", ""), ("background:#eee;color:#555", status))) gaps = "".join("
  • %s
  • " % htmllib.escape(g) for g in q.get("gaps", [])) gaps_html = "" % gaps if gaps else "" flags = "".join("
  • %s
  • " % htmllib.escape(f) for f in q.get("review_flags", [])) flags_html = ('

    Review carefully:

    ' % flags) if flags else "" lead = q.get("lead") or {} lead_html = "" if lead.get("tier"): lc = {"HOT": "#c8102e", "WARM": "#b26a00", "COOL": "#555"}.get(lead["tier"], "#555") lead_html = ('

    [%s lead] %s

    ' % ( lc, lead["tier"], htmllib.escape("; ".join(lead.get("reasons", []))))) prop = q.get("proposal_pdf", "") prop_html = ("

    Proposal PDF: %s

    " % htmllib.escape(prop) if prop else "

    No proposal yet.

    ") live = q.get("live_url") live_html = ('

    Live link: %s

    ' % (htmllib.escape(live), htmllib.escape(live)) if live else "

    Live link pending Cloudflare connector (HTML attached to draft).

    ") draft = q.get("draft_id") draft_html = ("

    Customer draft: %s (in Sean's Gmail drafts, ready to review and send)

    " % htmllib.escape(q.get("draft_status", "")) if draft else "

    No customer draft.

    ") eng = q.get("engaged_config") or {} eng_html = "" if eng.get("model"): eng_html = "

    Engaged: %s · %s · %s%s

    " % ( htmllib.escape(eng.get("model", "")), htmllib.escape(eng.get("term", "")), htmllib.escape(eng.get("monthly", "")), (" · also interested in " + htmllib.escape(eng.get("addons", "")) if eng.get("addons") else "")) tm = ("$%s / month" % format(q["total_monthly"], ",.2f")) if q.get("total_monthly") else "-" model_line = htmllib.escape(str(q.get("model") or "?")) if q.get("model_recommended"): model_line += ' (engine-recommended)' cards.append("""
    %(company)s %(label)s

    %(contact)s · %(phone)s · %(email)s
    Model: %(model)s · Total: %(total)s · Lease: %(lease)s
    Valid until: %(valid)s · Built: %(built)s

    %(gaps)s %(flags)s %(lead)s %(prop)s %(live)s %(draft)s %(eng)s

    id: %(id)s

    """ % { "company": htmllib.escape(c.get("company", "?")), "contact": htmllib.escape(c.get("contact_name", "")), "phone": htmllib.escape(c.get("phone", "")), "email": htmllib.escape(c.get("email", "")), "model": model_line, "total": tm, "lease": ("$%s/mo" % format(q["lease_monthly"], ",.2f")) if q.get("lease_monthly") else "-", "valid": htmllib.escape(q.get("valid_until") or "-"), "built": htmllib.escape((q.get("built_at") or "")[:16]), "style": style, "label": htmllib.escape(label), "gaps": gaps_html, "prop": prop_html, "live": live_html, "draft": draft_html, "eng": eng_html, "id": htmllib.escape(q.get("id", "")), "flags": flags_html, "lead": lead_html, }) body = "\n".join(cards) if cards else "

    No quote requests yet.

    " page = """ Quote Ops Dashboard (Internal)

    Quote Ops Dashboard internal only · not linked publicly

    Updated %s · Pricing: 25%% margin, 63-mo FMV Universal lease, B&W $0.014 / color $0.08 per page.

    %s

    Workflow: request → priced → PDF + interactive built → customer draft created for Sean's review → Sean sends. Costs and margins never leave this page.

    """ % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M ET"), body) out = os.path.join(BASE, "dashboard", "index.html") open(out, "w").write(page) return out if __name__ == "__main__": print(render())