Converted files to unix format
This commit is contained in:
parent
9e57a47bb5
commit
4b95b70a04
6 changed files with 541 additions and 589 deletions
|
@ -226,52 +226,16 @@ def tags():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/search/<query>')
|
@app.route('/search', methods=['POST'])
|
||||||
def search(query):
|
def search():
|
||||||
quotes = Quote.query.filter_by(approved=True).filter(Quote.content.ilike('%{}%'.format(query))).order_by(Quote.id.desc()).all()
|
if request.method == 'POST':
|
||||||
|
|
||||||
allquotes = len(quotes)
|
|
||||||
quotes = quotes[:10]
|
|
||||||
|
|
||||||
if len(quotes)>0:
|
|
||||||
# Replace line breaks with html breaks and escape special characters
|
|
||||||
for quote in quotes:
|
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"search.html",
|
"message.html",
|
||||||
title="Search for: {}".format(query),
|
alertclass="alert-warning",
|
||||||
quotes=quotes,
|
message="Not implemented yet. "
|
||||||
numpages=1 + allquotes//10,
|
|
||||||
curpage=0,
|
|
||||||
page_type="search",
|
|
||||||
search_query=query
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes in the database.")
|
return 'Invalid request.'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/search/<query>/<int:page>')
|
|
||||||
def search_page(query, page):
|
|
||||||
allquotes = len(Quote.query.filter_by(approved=True).\
|
|
||||||
filter(Quote.content.ilike('%{}%'.format(query))).\
|
|
||||||
order_by(Quote.id.desc()).all())
|
|
||||||
quotes = Quote.query.filter_by(approved=True).\
|
|
||||||
filter(Quote.content.ilike('%{}%'.format(query))).\
|
|
||||||
order_by(Quote.id.desc()).all()[(page-1)*10:page*10]
|
|
||||||
|
|
||||||
for quote in quotes:
|
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
"search.html",
|
|
||||||
title="Search for: {} - page {}".format(query, page),
|
|
||||||
quotes=quotes,
|
|
||||||
numpages=1 + allquotes//10,
|
|
||||||
curpage=page-1,
|
|
||||||
page_type="search",
|
|
||||||
search_query=query
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/add', methods=['GET', 'POST'])
|
@app.route('/add', methods=['GET', 'POST'])
|
||||||
|
@ -302,19 +266,7 @@ def add_new():
|
||||||
)
|
)
|
||||||
|
|
||||||
elif request.form['submit'] == "Preview":
|
elif request.form['submit'] == "Preview":
|
||||||
preview = Quote(request.form['newquote'], request.remote_addr, timestamp())
|
return str(request.form)
|
||||||
preview_tags = request.form["tags"].split(',')
|
|
||||||
preview.approved = True
|
|
||||||
preview.tags = [Tag(tag) for tag in preview_tags]
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
"latest.html",
|
|
||||||
title="Quote preview",
|
|
||||||
quotes=[preview,],
|
|
||||||
numpages=1,
|
|
||||||
curpage=0,
|
|
||||||
page_type="quote"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
abort(501)
|
abort(501)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue