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
slots.py · 1.7 KB · 48 lines
1"""Shared slot registry, served at /slots as window.dbbasicSlots.
2
3Named extension points for the generated list/form UIs (Phase 5b, page hooks —
4docs/upgrade-and-customization.md Rule 4). An operator or a page registers a
5renderer for a (collection, slot) pair; the generators call it at the matching
6hook point and inject its HTML — so behavior can be added to every list/form
7without editing the page or the generator itself. Register against a specific
8collection or "*" for all collections.
9
10Slots today:
11 /list -> before_list(ctx), after_list(ctx), row_actions(record), empty(ctx)
12 /form -> before_fields(ctx), after_fields(ctx)
13A renderer receives a context object and returns an HTML string (or "").
14Interactive slot markup should attach its own delegated listeners (list/form
15mounts re-render), e.g. document.addEventListener on a data-attribute.
16
17Defined once here; the generators call window.dbbasicSlots when present and
18no-op when it is absent, so slots are purely additive.
19"""
20
21_JS = r"""
22(function () {
23 const reg = {};
24 const key = (collection, slot) => collection + "::" + slot;
25 window.dbbasicSlots = {
26 register: function (collection, slot, fn) {
27 if (typeof fn !== "function") return;
28 const k = key(collection, slot);
29 (reg[k] = reg[k] || []).push(fn);
30 },
31 render: function (collection, slot, ctx) {
32 let out = "";
33 for (const scope of [collection, "*"]) {
34 const fns = reg[key(scope, slot)];
35 if (!fns) continue;
36 for (const fn of fns) {
37 try { const html = fn(ctx); if (html) out += html; } catch (e) {}
38 }
39 }
40 return out;
41 }
42 };
43})();
44"""
45
46
47def GET(request):
48 return {"content_type": "application/javascript; charset=utf-8", "body": _JS}