Add API to get content of the user facing page

This commit is contained in:
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 ( CREATE TABLE IF NOT EXISTS user (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
passhash TEXT, passhash TEXT,
city TEXT,
enabled INTEGER DEFAULT 1 enabled INTEGER DEFAULT 1
); );
CREATE TABLE IF NOT EXISTS email ( CREATE TABLE IF NOT EXISTS email (
@ -116,6 +115,15 @@ class DB(object):
active INTEGER, active INTEGER,
FOREIGN KEY(user_id) REFERENCES user(id) 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): def user_token(self, email, password):
@ -157,6 +165,19 @@ class DB(object):
return None return None
return User(uid) 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 @property
def active_users(self): def active_users(self):
from user import User from user import User

View file

@ -9,7 +9,6 @@ from sendmail import sendmail
from session import SessionPlugin from session import SessionPlugin
from mastodon import Mastodon from mastodon import Mastodon
def url(route): def url(route):
return '%s://%s/%s' % ( return '%s://%s/%s' % (
request.urlparts.scheme, request.urlparts.scheme,
@ -79,8 +78,7 @@ def login_post():
@get('/city/<city>') @get('/city/<city>')
@view('template/user-facing.tpl') @view('template/user-facing.tpl')
def city_page(city): def city_page(city):
# :todo how can we transfer the city name to the wrapper template? return db.user_facing_properties(city)
return dict(title=city)
@get('/settings') @get('/settings')