Add API to get content of the user facing page

multi-deployment
b3yond 2018-04-27 01:20:37 +02:00
parent 5ec4d1aab0
commit 9274dfdecb
2 changed files with 23 additions and 4 deletions

23
db.py
View File

@ -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

View File

@ -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/<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')