Move brand names to g, basic queue page
This commit is contained in:
parent
d034d8e989
commit
245377b17a
6 changed files with 54 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from flask import Flask
|
||||
from flask import Flask, g
|
||||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
from . import config, log
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% if title %}
|
||||
<title>{{ title }} - {{ appname }}</title>
|
||||
<title>{{ title }} - {{ g.appname }}</title>
|
||||
{% endif %}
|
||||
</head>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
|||
<div class="container" style="height:50%">
|
||||
<nav class="navbar navbar-default navbar-upper">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand navbar-brand-upper" href="">{{ appbrand }}</a>
|
||||
<a class="navbar-brand navbar-brand-upper" href="">{{ g.appbrand }}</a>
|
||||
</div>
|
||||
</nav>
|
||||
<nav class="navbar navbar-static-top navbar-lower">
|
||||
|
@ -31,6 +31,9 @@
|
|||
<li> <a href="/tags">Tags</a> </li>
|
||||
<li> <a href="/add">Add new</a> </li>
|
||||
<li> <a href="/login">Log in</a> </li>
|
||||
{% if session.authorized %}
|
||||
<li> <a href="/queue">Queue</a> </li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% if authorized %}
|
||||
{% if session.authorized %}
|
||||
|
||||
<center>
|
||||
<h3><br />Authorization key accepted<br /><br />Access granted</h3>
|
||||
|
|
23
smash/templates/queue.html
Normal file
23
smash/templates/queue.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% if quotes %}
|
||||
{% for quote in quotes %}
|
||||
<a class="quote-link" href="quote/{{ quote.id }}">#{{ quote.id }}</a>
|
||||
<a class="rate-positive">+</a> ({{quote.rating}}) <a class="rate-negative">-</a></br>
|
||||
<div class="quote">
|
||||
<p>{{ quote.content|safe }}</p>
|
||||
</div>
|
||||
|
||||
<div class="tags">
|
||||
|
||||
Tags:
|
||||
{% for tag in quote.tags %}
|
||||
<a href="tag/{{tag.name}}" class="badge"> {{tag.name}} </a>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -2,7 +2,7 @@
|
|||
{% block content %}
|
||||
|
||||
{% for tag in tags %}
|
||||
<a class="badge">{{tag}}</a><br />
|
||||
<a class="badge">{{tag.name}}</a><br />
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
import logging
|
||||
import psycopg2
|
||||
from flask import render_template, Markup, request, abort, session
|
||||
from flask import render_template, Markup, request, abort, session, g
|
||||
|
||||
from smash.models_sqlalchemy import *
|
||||
from smash import app, conf, db
|
||||
|
@ -11,6 +11,12 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def timestamp():
|
||||
return datetime.datetime.now().strftime("%H:%M:%S %d/%m/%y")
|
||||
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.appname = conf.config['APPNAME']
|
||||
g.appbrand = conf.config['APPBRAND']
|
||||
|
||||
|
||||
@app.route('/')
|
||||
|
@ -24,8 +30,6 @@ def index():
|
|||
|
||||
return render_template(
|
||||
"index.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
title="Quotes",
|
||||
welcometext=welcome,
|
||||
newstext=news
|
||||
|
@ -40,9 +44,6 @@ def login_page():
|
|||
|
||||
return render_template(
|
||||
"login.html",
|
||||
authorized=session.get('authorized', None),
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND']
|
||||
)
|
||||
|
||||
|
||||
|
@ -56,13 +57,26 @@ def latest():
|
|||
|
||||
return render_template(
|
||||
"latest.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
title="Latest",
|
||||
quotes=quotes
|
||||
)
|
||||
|
||||
|
||||
@app.route('/queue')
|
||||
def queue():
|
||||
quotes = Quote.query.filter_by(approved=False).order_by(Quote.id).all()
|
||||
|
||||
# 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(
|
||||
"queue.html",
|
||||
title="Queue",
|
||||
quotes=quotes
|
||||
)
|
||||
|
||||
|
||||
@app.route('/quote/<int:id>')
|
||||
def quote(id):
|
||||
quote = Quote.query.filter_by(id=id, approved=True).first()
|
||||
|
@ -77,8 +91,6 @@ def quote(id):
|
|||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||
return render_template(
|
||||
"latest.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
title="Quote #{}".format(quote.id),
|
||||
quotes=[quote,]
|
||||
)
|
||||
|
@ -86,12 +98,10 @@ def quote(id):
|
|||
|
||||
@app.route('/tags')
|
||||
def tags():
|
||||
tags = [x[0] for x in db.select("tags", "name")]
|
||||
tags = Tag.query.order_by(Tag.name).all()
|
||||
|
||||
return render_template(
|
||||
"tags.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
title="Tags",
|
||||
tags=tags
|
||||
)
|
||||
|
@ -126,8 +136,6 @@ def add_new():
|
|||
|
||||
return render_template(
|
||||
"message.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
alertclass="alert-success",
|
||||
message="Quote added succesfully. It will need to be reviewed by the administrators before it shows up."
|
||||
)
|
||||
|
@ -140,7 +148,5 @@ def add_new():
|
|||
elif request.method == 'GET':
|
||||
return render_template(
|
||||
"add.html",
|
||||
appname=conf.config['APPNAME'],
|
||||
appbrand=conf.config['APPBRAND'],
|
||||
title="Add new"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue