diff --git a/db.py b/db.py index 0650173..8e8d877 100644 --- a/db.py +++ b/db.py @@ -4,7 +4,7 @@ db = connection.smash qdb = db.quotes adb = db.accounts -live_quotes_count = lambda: qdb.find({ "hidden": False, "approved": True }) +count_live_quotes = lambda: qdb.find({ "hidden": False, "approved": True }).count() quote_live = lambda quote_id: bool(qdb.find_one({ "hidden": False, "approved": True })) tag_live = lambda tag: bool(qdb.find_one({ "hidden": False, "approved": True, "tags": tag })) diff --git a/main.py b/main.py index dd29240..f22ebcd 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import db from config import config app = Flask(__name__) +app.secret_key = config['secret-key'] #Connect to and define db connection = pymongo.MongoClient() @@ -25,20 +26,24 @@ def message(level, msg): def index(): news = "No quotes yet!" welcome = config['MOTD'] - #print(qdb.find().count()) - qCount = qdb.find({"hidden": False}).count() - #print(type(qCount)) - news = "Home of " + "5" + " dumb quotes!" - if qCount > 0: - rand_quote = db.get_random_quote() - quote_text = Markup.escape(rand_quote['quote']) if rand_quote else "There are no quotes in the database!" - news = quote_text - permalink = str(rand_quote['id']) + quotes_count = db.count_live_quotes() + + if ( quotes_count > 0 ) and ( config['random-quote'] ): + random_quote = db.get_random_quote() + news = Markup.escape(random_quote['quote']) + permalink = str(random_quote['id']) + elif ( quotes_count > 0 ): + news = "Home of " + str(quotes_count) + " quotes!" + permalink = None + else: + news = "There are no quotes in the database!" + permalink = None + return render_template( "index.html", - title="Quotes" + config["site-name"], - welcometext=welcome, + title="Quotes - " + config["site-name"], + header=welcome, newstext=news, permalink=permalink ) diff --git a/templates/index.html b/templates/index.html index ef724ee..2bcc1a1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,10 +6,11 @@ {% block content %}
{% endblock %}