From 9274dfdecbbdd64ddc8394a7355b031ef8da1c4d Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 27 Apr 2018 01:20:37 +0200 Subject: [PATCH] Add API to get content of the user facing page --- db.py | 23 ++++++++++++++++++++++- frontend.py | 4 +--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/db.py b/db.py index ea22592..abafec1 100644 --- a/db.py +++ b/db.py @@ -31,7 +31,6 @@ class DB(object): CREATE TABLE IF NOT EXISTS user ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, passhash TEXT, - city TEXT, enabled INTEGER DEFAULT 1 ); CREATE TABLE IF NOT EXISTS email ( @@ -116,6 +115,15 @@ class DB(object): active INTEGER, FOREIGN KEY(user_id) REFERENCES user(id) ); + CREATE TABLE IF NOT EXISTS cities ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, + user_id INTEGER, + city TEXT, + markdown TEXT, + masto_link TEXT, + twit_link TEXT, + FOREIGN KEY(user_id) REFERENCES user(id) + ); ''') def user_token(self, email, password): @@ -157,6 +165,19 @@ class DB(object): return None return User(uid) + def user_facing_properties(self, city): + self.execute("""SELECT city, markdown, masto_link, twit_link + FROM cities + WHERE city=?;""", (city, )) + try: + city, markdown, masto_link, twit_link = self.cur.fetchone() + return dict(city=city, + markdown=markdown, + masto_link=masto_link, + twit_link=twit_link) + except TypeError: + return None + @property def active_users(self): from user import User diff --git a/frontend.py b/frontend.py index 1892ad5..5975b2a 100755 --- a/frontend.py +++ b/frontend.py @@ -9,7 +9,6 @@ from sendmail import sendmail from session import SessionPlugin from mastodon import Mastodon - def url(route): return '%s://%s/%s' % ( request.urlparts.scheme, @@ -79,8 +78,7 @@ def login_post(): @get('/city/') @view('template/user-facing.tpl') def city_page(city): - # :todo how can we transfer the city name to the wrapper template? - return dict(title=city) + return db.user_facing_properties(city) @get('/settings')