Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
payments.py · 3.0 KB · 81 lines
1"""Payments page — built from metadata, not markup.
2
3The list (a live table: invoice, amount, method, status with filters) and the
4record form both come from the schema via the shared generators; this page is
5only chrome. The real business logic lives elsewhere by doctrine
6(docs/business-logic-patterns.md): hook_payments gates overpayment,
7hook_refunds gates and stamps refunds, and the invoice's paid/balance amounts
8are rollups/formulas that update live as payments land.
9"""
10
11_SCRIPT = """
12const panel = document.getElementById("formpanel");
13const list = window.dbbasicList("payments", {
14 mount: "#list", search: "#search", sort: "#sort", owner: OWNER_ID,
15 title: (r) => (r.reference || r.method || "payment") + " — " + (r.amount_cents || "0") + "c",
16 created: (r) => r.created_at, onEdit: (r) => openForm(r),
17});
18function openForm(record) {
19 document.getElementById("formtitle").textContent = record ? "Edit Payment" : "New Payment";
20 panel.style.display = "block";
21 window.dbbasicForm("payments", {
22 mount: "#formmount", record: record, owner: OWNER_ID,
23 onSaved: () => { panel.style.display = "none"; list.reload(); },
24 onCancel: () => { panel.style.display = "none"; },
25 });
26}
27document.getElementById("add").addEventListener("click", () => openForm(null));
28"""
29
30
31def GET(request):
32 identity = request.get("_identity", {})
33 user_id = identity.get("user_id")
34 _logger.info("site_payments served", user_id=user_id or "anonymous")
35
36 if not user_id:
37 body = '<p class="hint"><a href="/login?next=/payments">Sign in</a> to see payments.</p>'
38 script = ""
39 else:
40 body = """
41<div class="breadcrumb"><a href="/">Home</a> / Payments</div>
42<div class="pagehead"><h1>Payments</h1><button class="btn primary" id="add">+ New Payment</button></div>
43<div id="formpanel" style="display:none; margin-bottom:1rem">
44 <h2 id="formtitle" style="font-size:1rem; margin:0 0 0.5rem">New Payment</h2>
45 <div id="formmount"></div>
46</div>
47<div class="toolbar">
48 <input class="search grow" id="search" placeholder="Search payments&hellip;" autocomplete="off">
49 <select id="sort"><option value="newest">Newest</option><option value="oldest">Oldest</option></select>
50</div>
51<div id="list"><div class="state">loading&hellip;</div></div>
52"""
53 script = (
54 f"<script>const OWNER_ID = {user_id!r};</script>"
55 '<script src="/list"></script><script src="/form"></script>'
56 f"<script>{_SCRIPT}</script>"
57 )
58
59 who = (
60 f"signed in as <strong>{user_id}</strong>"
61 if user_id
62 else '<a href="/login?next=/payments">sign in</a>'
63 )
64 html = f"""<!doctype html>
65<html lang="en">
66<head>
67<meta charset="utf-8">
68<meta name="viewport" content="width=device-width, initial-scale=1">
69<title>Payments</title>
70<link rel="stylesheet" href="/style">
71</head>
72<body>
73<div class="wrap">
74<header class="app"><h1><a href="/">DBBASIC</a></h1><div class="who">{who}</div></header>
75{body}
76</div>
77{script}
78<script src="/nav"></script>
79</body>
80</html>"""
81 return {"content_type": "text/html; charset=utf-8", "body": html}