The hompeage now shows a random quote instead of a news thing
This commit is contained in:
parent
60f529cfb9
commit
165d3b4eb6
1 changed files with 305 additions and 300 deletions
|
@ -1,4 +1,5 @@
|
|||
import datetime
|
||||
import random
|
||||
import logging
|
||||
import psycopg2
|
||||
from flask import render_template, Markup, request, abort, session, g
|
||||
|
@ -37,6 +38,14 @@ def index():
|
|||
conf.config['APPNAME']
|
||||
)
|
||||
|
||||
#Show random quote on the homepage if any exist
|
||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc())all()
|
||||
numOfQuotes = len(quotes)
|
||||
if len(quotes)>0:
|
||||
quoteNum = random.choice(range(1,numOfQuotes+1))
|
||||
quote = quotes[quoteNum]
|
||||
news = str(Markup.escape(quote.content)).replace('\n', '<br />')
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
title="Quotes",
|
||||
|
@ -131,10 +140,6 @@ def moderate():
|
|||
|
||||
elif request.form['submit'] == "Delete":
|
||||
quote = Quote.query.filter_by(id=request.form['quoteid']).first()
|
||||
# Delete dangling tags (alive only with current Quote)
|
||||
dangling_tags = [tag for tag in quote.tags if tag.quotes.count() == 1]
|
||||
for tag in dangling_tags:
|
||||
db.session.delete(tag)
|
||||
db.session.delete(quote)
|
||||
db.session.commit()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue