Implement some config settings

This commit is contained in:
Kate 2020-11-20 23:33:27 +00:00
parent adae09c3d2
commit f3c587b124
3 changed files with 22 additions and 16 deletions

2
db.py
View file

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

27
main.py
View file

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

View file

@ -6,10 +6,11 @@
{% block content %}
<div class="container">
<div class="jumbotron">
<h1>{{ title }}</h1>
<p>{{ welcometext }}</p>
<pre>{{ newstext|safe }}</pre>
<a href="/quote/{{permalink}}">Permalink</a>
<h1>{{ header }}</h1>
<div class="card card-body bg-light mb-2"><pre class="mb-0">{{ newstext|safe }}</pre></div>
{% if permalink %}
<a href="/quote/{{ permalink }}">Permalink</a>
{% endif %}
</div>
</div>
{% endblock %}