Generic message template, tags in the main view, added required approval to quotes
This commit is contained in:
parent
8388a1e6b6
commit
7963e73a92
3 changed files with 62 additions and 13 deletions
|
@ -14,6 +14,7 @@ class Quote(Model):
|
||||||
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
|
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
|
||||||
rating = ("rating", "INTEGER", "NOT NULL")
|
rating = ("rating", "INTEGER", "NOT NULL")
|
||||||
content = ("content", "TEXT", "NOT NULL")
|
content = ("content", "TEXT", "NOT NULL")
|
||||||
|
approved = ("approved", "BOOLEAN", "NOT NULL")
|
||||||
|
|
||||||
|
|
||||||
class Tag(Model):
|
class Tag(Model):
|
||||||
|
|
8
smash/templates/message.html
Normal file
8
smash/templates/message.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="alert {{alertclass}}">
|
||||||
|
{{message}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -30,15 +30,32 @@ def index():
|
||||||
|
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
def latest():
|
def latest():
|
||||||
quotes = reversed(db.select("quotes", "id, rating, content"))
|
quotes = reversed(db.select("quotes", "id, rating, content", "approved"))
|
||||||
quotes = [(q[0], q[1], bytes(Markup.escape(q[2]), 'utf-8').decode('utf-8').replace('\n', '</br>')) for q in quotes]
|
quotes = [(q[0], q[1], unicode(Markup.escape(q[2])).replace('\n', '</br>')) for q in quotes]
|
||||||
|
|
||||||
|
quotes_tags = []
|
||||||
|
|
||||||
|
for quote in quotes:
|
||||||
|
tags = db.select("tagsToQuotes", "tagid", "quoteid='{}'".format(quote[0]))
|
||||||
|
tags_str = []
|
||||||
|
for tag in tags:
|
||||||
|
tags_str.append(db.select("tags", "name", "id='{}'".format(tag[0]))[0][0])
|
||||||
|
|
||||||
|
quotes_tags.append(
|
||||||
|
(
|
||||||
|
quote[0],
|
||||||
|
quote[1],
|
||||||
|
quote[2],
|
||||||
|
tags_str
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
appname=conf.config['APPNAME'],
|
appname=conf.config['APPNAME'],
|
||||||
appbrand=conf.config['APPBRAND'],
|
appbrand=conf.config['APPBRAND'],
|
||||||
title="Latest",
|
title="Latest",
|
||||||
quotes=quotes
|
quotes=quotes_tags
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +63,11 @@ def latest():
|
||||||
def quote(id):
|
def quote(id):
|
||||||
quote = db.select("quotes", "id, rating, content", "id='{}'".format(id))
|
quote = db.select("quotes", "id, rating, content", "id='{}'".format(id))
|
||||||
if len(quote)<1:
|
if len(quote)<1:
|
||||||
return "No such quote."
|
return render_template(
|
||||||
|
"message.html",
|
||||||
|
alertclass="alert-warning",
|
||||||
|
message="No such quote."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
tags = db.select("tagsToQuotes", "tagid", "quoteid='{}'".format(quote[0][0]))
|
tags = db.select("tagsToQuotes", "tagid", "quoteid='{}'".format(quote[0][0]))
|
||||||
|
@ -58,7 +79,7 @@ def quote(id):
|
||||||
(
|
(
|
||||||
quote[0][0],
|
quote[0][0],
|
||||||
quote[0][1],
|
quote[0][1],
|
||||||
bytes(Markup.escape(quote[0][2]), 'utf-8').decode('utf-8').replace('\n', '</br>'),
|
unicode(Markup.escape(quote[0][2])).replace('\n', '</br>'),
|
||||||
tags_str
|
tags_str
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
@ -84,7 +105,11 @@ def tags():
|
||||||
@app.route('/search', methods=['POST'])
|
@app.route('/search', methods=['POST'])
|
||||||
def search():
|
def search():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return 'success'
|
return render_template(
|
||||||
|
"message.html",
|
||||||
|
alertclass="alert-warning",
|
||||||
|
message="Not implemented yet. "
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return 'Invalid request.'
|
return 'Invalid request.'
|
||||||
|
|
||||||
|
@ -96,7 +121,12 @@ def add_new():
|
||||||
quote_body = request.form["newquote"]
|
quote_body = request.form["newquote"]
|
||||||
quote_tags = request.form["tags"].split(',')
|
quote_tags = request.form["tags"].split(',')
|
||||||
|
|
||||||
cur = db.insert("quotes", "rating, content", "?, ?", (0, quote_body) )
|
cur = db.insert(
|
||||||
|
"quotes",
|
||||||
|
"rating, content, approved",
|
||||||
|
"?, ?, ?",
|
||||||
|
(0, quote_body, 0)
|
||||||
|
)
|
||||||
qid = cur.lastrowid
|
qid = cur.lastrowid
|
||||||
|
|
||||||
for tag in quote_tags:
|
for tag in quote_tags:
|
||||||
|
@ -122,6 +152,16 @@ def add_new():
|
||||||
)
|
)
|
||||||
except sqlite3.Error:
|
except sqlite3.Error:
|
||||||
logger.warning("Database error while inserting into tagsToQuotes")
|
logger.warning("Database error while inserting into tagsToQuotes")
|
||||||
|
return render_template(
|
||||||
|
"message.html",
|
||||||
|
alertclass="alert-danger",
|
||||||
|
message="Could not add your quote. Try again later."
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"message.html",
|
||||||
|
alertclass="alert-success",
|
||||||
|
message="Quote added succesfully. It will need to be reviewed by the administrators before it shows up."
|
||||||
|
)
|
||||||
|
|
||||||
elif request.form['submit'] == "Preview":
|
elif request.form['submit'] == "Preview":
|
||||||
return str(request.form)
|
return str(request.form)
|
||||||
|
|
Loading…
Add table
Reference in a new issue