A form builder that keeps forms and responses in TSV files: git-friendly, no database, CSV export.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-forms.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-forms.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-forms.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 Fix API handlers for dbbasic-web compatibility (v1.0.1) 143a3f2 1 year, 1 month ago History
responses.py · 1.2 KB · 45 lines
1"""
2View form responses (admin interface)
3GET /admin/forms/{form_id}/responses - Show responses page
4"""
5
6import json
7from pathlib import Path
8from dbbasic_forms import FormBuilder
9
10
11def handle(request):
12 """Show form responses interface"""
13 # Extract form_id from path
14 # Path format: /admin/forms/{form_id}/responses
15 path_parts = request.path.strip("/").split("/")
16 if len(path_parts) < 3:
17 return {
18 "status": 400,
19 "headers": {"Content-Type": "application/json"},
20 "body": json.dumps({"error": "Invalid path"}),
21 }
22
23 form_id = path_parts[2] # forms/{form_id}/responses
24
25 # Load form
26 builder = FormBuilder()
27 form = builder.get_form(form_id)
28
29 if not form:
30 return {
31 "status": 404,
32 "headers": {"Content-Type": "application/json"},
33 "body": json.dumps({"error": "Form not found"}),
34 }
35
36 # Load responses template
37 template_path = Path(__file__).parent.parent.parent / "templates" / "forms" / "responses.html"
38 with open(template_path) as f:
39 html = f.read()
40
41 return {
42 "status": 200,
43 "headers": {"Content-Type": "text/html"},
44 "body": html,
45 }