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
post.py · 693 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 | posts = TSV("posts", ["id", "username", "content", "created"]) |
| 8 | |
| 9 | def handle(request): |
| 10 | user, auth_error = request.require_auth(accounts) |
| 11 | if auth_error: |
| 12 | return auth_error |
| 13 | |
| 14 | if request.method == 'POST': |
| 15 | content = request.param('content', '') |
| 16 | post_id = str(int(time.time() * 1000)) |
| 17 | |
| 18 | posts.insert({ |
| 19 | 'id': post_id, |
| 20 | 'username': user.username, |
| 21 | 'content': content, |
| 22 | 'created': time.strftime('%Y-%m-%d %H:%M') |
| 23 | }) |
| 24 | |
| 25 | return redirect('/') |