display correct number of bots on home page

This commit is contained in:
Lynne Megido 2019-09-01 20:24:45 +10:00
parent 6b24fb667b
commit 7eac3f6f11
3 changed files with 11 additions and 3 deletions

View File

@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `posts` (
`post_id` VARCHAR(64) NOT NULL,
`content` TEXT NOT NULL,
`cw` BOOLEAN NOT NULL,
FOREIGN KEY (`fedi_id`) REFERENCES fedi_account(handle) ON DELETE CASCADE;
FOREIGN KEY (`fedi_id`) REFERENCES fedi_account(handle) ON DELETE CASCADE
) ENGINE=INNODB;
CREATE TABLE IF NOT EXISTS `word_blacklist` (
`id` INT AUTO_INCREMENT PRIMARY KEY,

View File

@ -8,7 +8,7 @@
<body>
<div class="container light">
<h1 class='thin centred'>Home</h1>
<p class="centred large">Hi there! You have 1 bots, all of which are currently active.</p>
<p class="centred large">Hi there! You have {{ bot_count }} bot{% if bot_count != 1 %}s{% endif %}{% if bot_count != 0 %}, {{ active_count }} of which {% if active_count == 1 %}is{% else %}are{% endif %} currently active.{% else %}.{% endif %}</p>
<p class="centred" style="margin: 50px 0;">
<a class="button btn-primary btn-large" href="/bot/create" role="button"><i class="fas fa-robot"></i> New bot</a>
<a class="button btn-secondary btn-large" href="/settings" role="button"><i class="fas fa-cog"></i> Account settings</a>

View File

@ -20,7 +20,15 @@ mysql = MySQL(app)
def home():
if 'userid' in session:
session['step'] = 1
return render_template("home.html")
c = mysql.connection.cursor()
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s", (session['userid'],))
bot_count = c.fetchone()[0]
active_count = None
if bot_count > 0:
c.execute("SELECT COUNT(*) FROM `bots` WHERE user_id = %s AND enabled = TRUE", (session['userid'],))
active_count = c.fetchone()[0]
c.close()
return render_template("home.html", bot_count = bot_count, active_count = active_count)
else:
return render_template("front_page.html")