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
unfollow.py · 535 bytes · 18 lines
| 1 | from dbbasic.tsv import TSV |
| 2 | from dbbasic_web.responses import redirect |
| 3 | from dbbasic_accounts import Accounts |
| 4 | |
| 5 | accounts = Accounts('.', domain='localhost') |
| 6 | follows = TSV("follows", ["follower", "following", "created"]) |
| 7 | |
| 8 | def handle(request): |
| 9 | username = request.path_param(1) |
| 10 | if not username: |
| 11 | return redirect('/') |
| 12 | |
| 13 | user, auth_error = request.require_auth(accounts) |
| 14 | if auth_error: |
| 15 | return auth_error |
| 16 | |
| 17 | follows.delete(follower=user.username, following=username) |
| 18 | return redirect(f'/profile/{username}') |