Implement some config settings
This commit is contained in:
parent
adae09c3d2
commit
f3c587b124
3 changed files with 22 additions and 16 deletions
2
db.py
2
db.py
|
@ -4,7 +4,7 @@ db = connection.smash
|
||||||
qdb = db.quotes
|
qdb = db.quotes
|
||||||
adb = db.accounts
|
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 }))
|
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 }))
|
tag_live = lambda tag: bool(qdb.find_one({ "hidden": False, "approved": True, "tags": tag }))
|
||||||
|
|
||||||
|
|
27
main.py
27
main.py
|
@ -4,6 +4,7 @@ import db
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.secret_key = config['secret-key']
|
||||||
|
|
||||||
#Connect to and define db
|
#Connect to and define db
|
||||||
connection = pymongo.MongoClient()
|
connection = pymongo.MongoClient()
|
||||||
|
@ -25,20 +26,24 @@ def message(level, msg):
|
||||||
def index():
|
def index():
|
||||||
news = "No quotes yet!"
|
news = "No quotes yet!"
|
||||||
welcome = config['MOTD']
|
welcome = config['MOTD']
|
||||||
#print(qdb.find().count())
|
quotes_count = db.count_live_quotes()
|
||||||
qCount = qdb.find({"hidden": False}).count()
|
|
||||||
#print(type(qCount))
|
if ( quotes_count > 0 ) and ( config['random-quote'] ):
|
||||||
news = "Home of " + "5" + " dumb quotes!"
|
random_quote = db.get_random_quote()
|
||||||
if qCount > 0:
|
news = Markup.escape(random_quote['quote'])
|
||||||
rand_quote = db.get_random_quote()
|
permalink = str(random_quote['id'])
|
||||||
quote_text = Markup.escape(rand_quote['quote']) if rand_quote else "There are no quotes in the database!"
|
elif ( quotes_count > 0 ):
|
||||||
news = quote_text
|
news = "Home of " + str(quotes_count) + " quotes!"
|
||||||
permalink = str(rand_quote['id'])
|
permalink = None
|
||||||
|
else:
|
||||||
|
news = "There are no quotes in the database!"
|
||||||
|
permalink = None
|
||||||
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
title="Quotes" + config["site-name"],
|
title="Quotes - " + config["site-name"],
|
||||||
welcometext=welcome,
|
header=welcome,
|
||||||
newstext=news,
|
newstext=news,
|
||||||
permalink=permalink
|
permalink=permalink
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ header }}</h1>
|
||||||
<p>{{ welcometext }}</p>
|
<div class="card card-body bg-light mb-2"><pre class="mb-0">{{ newstext|safe }}</pre></div>
|
||||||
<pre>{{ newstext|safe }}</pre>
|
{% if permalink %}
|
||||||
<a href="/quote/{{permalink}}">Permalink</a>
|
<a href="/quote/{{ permalink }}">Permalink</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue