Replace the generic records table with a lean join_leads table
records was a leads table wearing a generic name. It carried display_name / email / phone, which only mean anything for a lead, plus status / assigned_to / notes, which were a guess at an outreach process that has not been designed. Contacting a family is one-to-many, so three columns on the lead row was always the wrong shape for it. join_leads is one row per /join submission with one column per form field, two timestamps, and payload holding the submission verbatim. Outreach gets its own table when the process is actually known. Also splits heard_from from heard_from_detail. app.py folded source_place / source_other into a composed "Other: ..." string and threw the raw answer away, which is the half that tells you which daycare the lead came from. The composed value is still built for the Sheet and the ntfy push. admin API: /records -> /leads, and PATCH is gone since a lead now has nothing mutable on it. mirrors and meta are unchanged.
This commit is contained in:
+11
-7
@@ -623,10 +623,14 @@ def pipeline_notify(rec, sheet_error=None):
|
||||
def join_post(parent_name: str = Form(...), email: str = Form(...), phone: str = Form(""),
|
||||
children: str = Form(""), interested_in: str = Form(""), source: str = Form(""),
|
||||
source_place: str = Form(""), source_other: str = Form(""), message: str = Form("")):
|
||||
heard_from = source.strip()
|
||||
heard_from_detail = ""
|
||||
if source == "Other school or daycare" and source_place.strip():
|
||||
source = "School/Daycare: " + source_place.strip()
|
||||
heard_from_detail = source_place.strip()
|
||||
source = "School/Daycare: " + heard_from_detail
|
||||
elif source == "Other" and source_other.strip():
|
||||
source = "Other: " + source_other.strip()
|
||||
heard_from_detail = source_other.strip()
|
||||
source = "Other: " + heard_from_detail
|
||||
rec = {"ts": datetime.datetime.now().isoformat(timespec="seconds"),
|
||||
"parent_name": parent_name.strip(), "email": email.strip(), "phone": phone.strip(),
|
||||
"children": children.strip() or "(not given)",
|
||||
@@ -642,11 +646,11 @@ def join_post(parent_name: str = Form(...), email: str = Form(...), phone: str =
|
||||
# against the record so a failure is replayable instead of just shouted.
|
||||
record_id = None
|
||||
try:
|
||||
record_id = store.insert_record(
|
||||
kind="join_lead", source=rec["source"], payload=rec,
|
||||
unit=store.unit_of(rec["interested_in"]),
|
||||
display_name=rec["parent_name"], email=rec["email"],
|
||||
phone=rec["phone"], created_at=rec["ts"])
|
||||
record_id = store.insert_lead(
|
||||
parent_name=rec["parent_name"], email=rec["email"], phone=rec["phone"],
|
||||
interested_in=rec["interested_in"], children=rec["children"],
|
||||
heard_from=heard_from, heard_from_detail=heard_from_detail,
|
||||
message=rec["message"], payload=rec, submitted_at=rec["ts"])
|
||||
except Exception as e:
|
||||
print("STORE WRITE FAILED for %s <%s>: %s" % (rec["parent_name"], rec["email"], e), flush=True)
|
||||
sheet_error = None
|
||||
|
||||
Reference in New Issue
Block a user