Read boards from a database
This commit is contained in:
parent
128f937a11
commit
161bb72d37
15
database.py
15
database.py
|
@ -70,7 +70,7 @@ def get_userid(db, username):
|
||||||
|
|
||||||
# Get the user ID
|
# Get the user ID
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('SELECT id FROM users WHERE username = ?', (username,))
|
cursor.execute('SELECT id FROM users WHERE username = ?;', (username,))
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
|
|
||||||
# If no user was found, return None
|
# If no user was found, return None
|
||||||
|
@ -87,7 +87,7 @@ def check_password(db, userid, password):
|
||||||
|
|
||||||
# Get the password and status
|
# Get the password and status
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('SELECT password, status FROM users WHERE id = ?', (userid,))
|
cursor.execute('SELECT password, status FROM users WHERE id = ?;', (userid,))
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
|
|
||||||
# If no user of that name, fail
|
# If no user of that name, fail
|
||||||
|
@ -107,7 +107,7 @@ def get_user_info(db, userid):
|
||||||
"""Returns a UserInfo object representing the data associated with a user
|
"""Returns a UserInfo object representing the data associated with a user
|
||||||
If no user was found, returns None"""
|
If no user was found, returns None"""
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('SELECT id, parent, status, username, email, comment FROM users WHERE id = ?', (userid,))
|
cursor.execute('SELECT id, parent, status, username, email, comment FROM users WHERE id = ?;', (userid,))
|
||||||
results = cursor.fetchall()
|
results = cursor.fetchall()
|
||||||
|
|
||||||
# If no user was found, return None
|
# If no user was found, return None
|
||||||
|
@ -152,8 +152,13 @@ def initialize_users(db, admin_user, admin_password):
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
def list_boards(db):
|
def list_boards(db):
|
||||||
# TODO: Implement this
|
"""Lists the boards that exist at the moment"""
|
||||||
...
|
cursor = db.cursor()
|
||||||
|
cursor.execute('SELECT name FROM boards;')
|
||||||
|
results = cursor.fetchall()
|
||||||
|
|
||||||
|
# The results look like [('foo',), ('bar',), ('baz',)]
|
||||||
|
return [i[0] for i in results]
|
||||||
|
|
||||||
def initialize_boards(db, boards):
|
def initialize_boards(db, boards):
|
||||||
"""Creates a table of boards
|
"""Creates a table of boards
|
||||||
|
|
|
@ -3,6 +3,7 @@ import urllib.parse
|
||||||
import bs4
|
import bs4
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
import database
|
||||||
|
|
||||||
def generate_nav(*, soup):
|
def generate_nav(*, soup):
|
||||||
"""Returns nav_tag"""
|
"""Returns nav_tag"""
|
||||||
|
@ -10,7 +11,10 @@ def generate_nav(*, soup):
|
||||||
nav_tag = soup.new_tag('nav')
|
nav_tag = soup.new_tag('nav')
|
||||||
|
|
||||||
# TODO: Read these from the database
|
# TODO: Read these from the database
|
||||||
for board in ['a', 'b', 'his', 'g']:
|
with database.connect() as db:
|
||||||
|
boards = database.list_boards(db)
|
||||||
|
|
||||||
|
for board in boards:
|
||||||
url = config.url_prefix + '/' + urllib.parse.quote(board, safe = '') + '/'
|
url = config.url_prefix + '/' + urllib.parse.quote(board, safe = '') + '/'
|
||||||
a_tag = soup.new_tag('a', href = url)
|
a_tag = soup.new_tag('a', href = url)
|
||||||
a_tag.string = '/' + board + '/'
|
a_tag.string = '/' + board + '/'
|
||||||
|
|
Loading…
Reference in New Issue