askrobots / dbbasic-examples
Public
Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.
danq9
Add official module template for creating DBBasic packages
17cf88a
1 year, 1 month ago
History
follow.py · 724 bytes · 25 lines
| 1 | from dbbasic.tsv import TSV |
| 2 | from dbbasic_web.responses import redirect |
| 3 | from dbbasic_accounts import Accounts |
| 4 | import time |
| 5 | |
| 6 | accounts = Accounts('.', domain='localhost') |
| 7 | follows = TSV("follows", ["follower", "following", "created"]) |
| 8 | |
| 9 | def handle(request): |
| 10 | username = request.path_param(1) |
| 11 | if not username: |
| 12 | return redirect('/') |
| 13 | |
| 14 | user, auth_error = request.require_auth(accounts) |
| 15 | if auth_error: |
| 16 | return auth_error |
| 17 | |
| 18 | if not follows.query_one(follower=user.username, following=username): |
| 19 | follows.insert({ |
| 20 | 'follower': user.username, |
| 21 | 'following': username, |
| 22 | 'created': time.strftime('%Y-%m-%d %H:%M') |
| 23 | }) |
| 24 | |
| 25 | return redirect(f'/profile/{username}') |