Converted files to unix format
This commit is contained in:
parent
9e57a47bb5
commit
4b95b70a04
6 changed files with 541 additions and 589 deletions
|
@ -1,49 +1,49 @@
|
||||||
import os
|
import os
|
||||||
from flask import Flask, g
|
from flask import Flask, g
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from . import config, log
|
from . import config, log
|
||||||
|
|
||||||
|
|
||||||
log.configure_logging()
|
log.configure_logging()
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
conf = config.Config('config.json')
|
conf = config.Config('config.json')
|
||||||
|
|
||||||
# Load database URL for SQLAlchemy from environment
|
# Load database URL for SQLAlchemy from environment
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
|
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
|
||||||
|
|
||||||
# This flag tells the program it's deployed on heroku
|
# This flag tells the program it's deployed on heroku
|
||||||
if 'HEROKU' in os.environ:
|
if 'HEROKU' in os.environ:
|
||||||
conf.add(('HEROKU', 1))
|
conf.add(('HEROKU', 1))
|
||||||
|
|
||||||
# Load app name from environment if it's not in the config
|
# Load app name from environment if it's not in the config
|
||||||
if ('APPNAME' in conf.config and
|
if ('APPNAME' in conf.config and
|
||||||
conf.config['APPNAME']=="" and
|
conf.config['APPNAME']=="" and
|
||||||
'APPNAME' in os.environ):
|
'APPNAME' in os.environ):
|
||||||
conf.add(('APPNAME', os.environ['APPNAME']))
|
conf.add(('APPNAME', os.environ['APPNAME']))
|
||||||
|
|
||||||
# Load app brand name from environment if it's not in the config
|
# Load app brand name from environment if it's not in the config
|
||||||
if ('APPBRAND' in conf.config and
|
if ('APPBRAND' in conf.config and
|
||||||
conf.config['APPBRAND']=="" and
|
conf.config['APPBRAND']=="" and
|
||||||
'APPBRAND' in os.environ):
|
'APPBRAND' in os.environ):
|
||||||
conf.add(('APPBRAND', os.environ['APPBRAND']))
|
conf.add(('APPBRAND', os.environ['APPBRAND']))
|
||||||
|
|
||||||
# Load admin key and secret key from environment
|
# Load admin key and secret key from environment
|
||||||
if 'ADMINSECRET' in os.environ:
|
if 'ADMINSECRET' in os.environ:
|
||||||
conf.add(('ADMINSECRET', os.environ['ADMINSECRET']))
|
conf.add(('ADMINSECRET', os.environ['ADMINSECRET']))
|
||||||
|
|
||||||
if 'SECRETKEY' in os.environ:
|
if 'SECRETKEY' in os.environ:
|
||||||
conf.add(('SECRETKEY', os.environ['SECRETKEY']))
|
conf.add(('SECRETKEY', os.environ['SECRETKEY']))
|
||||||
|
|
||||||
# Set the secret key
|
# Set the secret key
|
||||||
if 'SECRETKEY' in conf.config:
|
if 'SECRETKEY' in conf.config:
|
||||||
app.secret_key = conf.config['SECRETKEY']
|
app.secret_key = conf.config['SECRETKEY']
|
||||||
else:
|
else:
|
||||||
exit("Secret key not set.")
|
exit("Secret key not set.")
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
from smash.models_sqlalchemy import *
|
from smash.models_sqlalchemy import *
|
||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.config = json.loads(open(self.filename, 'r').read())
|
self.config = json.loads(open(self.filename, 'r').read())
|
||||||
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
with open(self.filename, 'w') as outf:
|
with open(self.filename, 'w') as outf:
|
||||||
outf.write(
|
outf.write(
|
||||||
json.dumps(
|
json.dumps(
|
||||||
self.config,
|
self.config,
|
||||||
indent=4,
|
indent=4,
|
||||||
sort_keys=True)
|
sort_keys=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
self.config = json.loads(open(self.filename, 'r').read())
|
self.config = json.loads(open(self.filename, 'r').read())
|
||||||
|
|
||||||
|
|
||||||
def add(self, param):
|
def add(self, param):
|
||||||
self.config[param[0]] = param[1]
|
self.config[param[0]] = param[1]
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
def remove(self, paramname):
|
def remove(self, paramname):
|
||||||
if self.config.get(paramname) is not None:
|
if self.config.get(paramname) is not None:
|
||||||
del self.config[paramname]
|
del self.config[paramname]
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
@ -1,161 +1,161 @@
|
||||||
html, body {
|
html, body {
|
||||||
font-family: 'Montserrat';
|
font-family: 'Montserrat';
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-image: url("../images/bg.png");
|
background-image: url("../images/bg.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-upper{
|
.navbar-upper{
|
||||||
margin-bottom: 0px;
|
margin-bottom: 0px;
|
||||||
min-height: 25px;
|
min-height: 25px;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
background-color: #03A9F4;
|
background-color: #03A9F4;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-default .navbar-brand-upper{
|
.navbar-default .navbar-brand-upper{
|
||||||
font-family: 'Rubik Mono One';
|
font-family: 'Rubik Mono One';
|
||||||
color: #FAFAFA;
|
color: #FAFAFA;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
line-height: 25px;
|
line-height: 25px;
|
||||||
text-shadow: -2px 2px 2px rgba(33, 33, 33, 0.85);
|
text-shadow: -2px 2px 2px rgba(33, 33, 33, 0.85);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-default .navbar-brand:hover{
|
.navbar-default .navbar-brand:hover{
|
||||||
color: #FAFAFA;
|
color: #FAFAFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-lower{
|
.navbar-lower{
|
||||||
min-height: 30px;
|
min-height: 30px;
|
||||||
background-color: #212121;
|
background-color: #212121;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
box-shadow: 0px 2px 10px 0px rgba(33, 33, 33, 0.85);
|
box-shadow: 0px 2px 10px 0px rgba(33, 33, 33, 0.85);
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-nav > li > a{
|
.navbar-nav > li > a{
|
||||||
padding: 10px 15px 10px 15px;
|
padding: 10px 15px 10px 15px;
|
||||||
color: #FAFAFA;
|
color: #FAFAFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav > li > a:hover{
|
.nav > li > a:hover{
|
||||||
background-color: #424242;
|
background-color: #424242;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-right{
|
.navbar-right{
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-form {
|
.navbar-form {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-form > .form-group{
|
.navbar-form > .form-group{
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-form > .form-group > .form-control {
|
.navbar-form > .form-group > .form-control {
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
border: 0;
|
border: 0;
|
||||||
border-bottom: 2px solid #FAFAFA;
|
border-bottom: 2px solid #FAFAFA;
|
||||||
background-color: inherit;
|
background-color: inherit;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
color: #FAFAFA
|
color: #FAFAFA
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-form > .form-group > .form-control:focus {
|
.navbar-form > .form-group > .form-control:focus {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
border-bottom: 2px solid #03A9F4;
|
border-bottom: 2px solid #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
background-color: #212121;
|
background-color: #212121;
|
||||||
box-shadow: 0 -2px 10px 0px rgba(33, 33, 33, 0.85);
|
box-shadow: 0 -2px 10px 0px rgba(33, 33, 33, 0.85);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
right: 0;
|
right: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: -50px;
|
bottom: -50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-copyright {
|
.footer-copyright {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #FAFAFA;
|
color: #FAFAFA;
|
||||||
font-variant: small-caps;
|
font-variant: small-caps;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quote-link {
|
.quote-link {
|
||||||
color: #424242;
|
color: #424242;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quote {
|
.quote {
|
||||||
font-family: 'Inconsolata', monospace;
|
font-family: 'Inconsolata', monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quote-header {
|
.quote-header {
|
||||||
background-color: #b3e5fc;
|
background-color: #b3e5fc;
|
||||||
border-bottom: 1px solid;
|
border-bottom: 1px solid;
|
||||||
border-color: #4fc3f7;
|
border-color: #4fc3f7;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.quote-date {
|
.quote-date {
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rate-positive {
|
.rate-positive {
|
||||||
color: #4caf50;
|
color: #4caf50;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rate-negative {
|
.rate-negative {
|
||||||
color: #f44336;
|
color: #f44336;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table-separator{
|
.table-separator{
|
||||||
background-color: #03A9F4;
|
background-color: #03A9F4;
|
||||||
padding: 0!important;
|
padding: 0!important;
|
||||||
width: 3px;
|
width: 3px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table{
|
.table{
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table > tbody > tr > td{
|
.table > tbody > tr > td{
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tags {
|
.tags {
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
background-color: #03A9F4;
|
background-color: #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mod-form {
|
.mod-form {
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-mod {
|
.btn-mod {
|
||||||
padding: 0px 4px;
|
padding: 0px 4px;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination {
|
.pagination {
|
||||||
|
@ -165,9 +165,9 @@ html, body {
|
||||||
|
|
||||||
.pagination>li>a {
|
.pagination>li>a {
|
||||||
color: #03A9F4;
|
color: #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pagination>.active>a {
|
.pagination>.active>a {
|
||||||
background-color: #03A9F4;
|
background-color: #03A9F4;
|
||||||
border-color: #03A9F4;
|
border-color: #03A9F4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<center>
|
<center>
|
||||||
<form action="/add" name="add" method="post">
|
<form action="/add" name="add" method="post">
|
||||||
<table width="60%">
|
<table width="60%">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
</br>
|
</br>
|
||||||
<textarea class="form-control" rows="10" name="newquote"></textarea>
|
<textarea class="form-control" rows="10" name="newquote"></textarea>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
</br>
|
</br>
|
||||||
<label for="tags" >Tags:</label>
|
<label for="tags" >Tags:</label>
|
||||||
<input class="form-control" type="text" name="tags" id="tags" value="" data-role="tagsinput" />
|
<input class="form-control" type="text" name="tags" id="tags" value="" data-role="tagsinput" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
</br>
|
</br>
|
||||||
<input type="submit" name="submit" value="Preview" class="btn btn-default"></input>
|
<input type="submit" name="submit" value="Preview" class="btn btn-default"></input>
|
||||||
<input type="submit" name="submit" value="Submit" class="btn btn-default"></input>
|
<input type="submit" name="submit" value="Submit" class="btn btn-default"></input>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
</br>
|
</br>
|
||||||
IP and connection time are logged.
|
IP and connection time are logged.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{{ welcometext|safe }}
|
{{ welcometext|safe }}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="table-separator">
|
<td class="table-separator">
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
{{ newstext|safe }}
|
{{ newstext|safe }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{{ msg|safe }}
|
{{ msg|safe }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
528
smash/views.py
528
smash/views.py
|
@ -1,17 +1,17 @@
|
||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from flask import render_template, Markup, request, abort, session, g
|
from flask import render_template, Markup, request, abort, session, g
|
||||||
|
|
||||||
from smash.models_sqlalchemy import *
|
from smash.models_sqlalchemy import *
|
||||||
from smash import app, conf, db
|
from smash import app, conf, db
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def timestamp():
|
def timestamp():
|
||||||
return datetime.datetime.now().strftime("%H:%M:%S %d/%m/%y")
|
return datetime.datetime.now().strftime("%H:%M:%S %d/%m/%y")
|
||||||
|
|
||||||
|
|
||||||
def message(level, msg):
|
def message(level, msg):
|
||||||
|
@ -27,16 +27,16 @@ def message(level, msg):
|
||||||
def before_request():
|
def before_request():
|
||||||
g.appname = conf.config['APPNAME']
|
g.appname = conf.config['APPNAME']
|
||||||
g.appbrand = conf.config['APPBRAND']
|
g.appbrand = conf.config['APPBRAND']
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
welcome = conf.config['MOTD']
|
welcome = conf.config['MOTD']
|
||||||
news = ("<p><b>{}</b></p><h4>{} running on smash quote database"
|
news = ("<p><b>{}</b></p><h4>{} running on smash quote database"
|
||||||
" engine launched today</h4>").format(
|
" engine launched today</h4>").format(
|
||||||
datetime.datetime.now().strftime("%d/%m/%y"),
|
datetime.datetime.now().strftime("%d/%m/%y"),
|
||||||
conf.config['APPNAME']
|
conf.config['APPNAME']
|
||||||
)
|
)
|
||||||
|
|
||||||
#Show random quote on the homepage if any exist
|
#Show random quote on the homepage if any exist
|
||||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
||||||
|
@ -45,56 +45,56 @@ def index():
|
||||||
quote = random.choice(quotes)
|
quote = random.choice(quotes)
|
||||||
news = str(Markup.escape(quote.content)).replace('\n', '<br />')
|
news = str(Markup.escape(quote.content)).replace('\n', '<br />')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"index.html",
|
"index.html",
|
||||||
title="Quotes",
|
title="Quotes",
|
||||||
welcometext=welcome,
|
welcometext=welcome,
|
||||||
newstext=news
|
newstext=news
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login_page():
|
def login_page():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if request.form["secret"] == conf.config['ADMINSECRET']:
|
if request.form["secret"] == conf.config['ADMINSECRET']:
|
||||||
session['authorized'] = True
|
session['authorized'] = True
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"login.html",
|
"login.html",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/latest')
|
@app.route('/latest')
|
||||||
def latest():
|
def latest():
|
||||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()
|
||||||
allquotes = len(quotes)
|
allquotes = len(quotes)
|
||||||
quotes = quotes[:10]
|
quotes = quotes[:10]
|
||||||
|
|
||||||
if len(quotes)>0:
|
if len(quotes)>0:
|
||||||
# Replace line breaks with html breaks and escape special characters
|
# Replace line breaks with html breaks and escape special characters
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Latest",
|
title="Latest",
|
||||||
quotes=quotes,
|
quotes=quotes,
|
||||||
numpages=1 + allquotes//10 if allquotes%10 != 0 else allquotes//10,
|
numpages=1 + allquotes//10 if allquotes%10 != 0 else allquotes//10,
|
||||||
curpage=0,
|
curpage=0,
|
||||||
page_type="latest"
|
page_type="latest"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes in the database.")
|
return message("alert-warning", "No quotes in the database.")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/latest/<int:page>')
|
@app.route('/latest/<int:page>')
|
||||||
def latest_page(page):
|
def latest_page(page):
|
||||||
allquotes = len(Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all())
|
allquotes = len(Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all())
|
||||||
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()[(page-1)*10:page*10]
|
quotes = Quote.query.filter_by(approved=True).order_by(Quote.id.desc()).all()[(page-1)*10:page*10]
|
||||||
|
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Latest - page {}".format(page),
|
title="Latest - page {}".format(page),
|
||||||
|
@ -104,222 +104,174 @@ def latest_page(page):
|
||||||
page_type="latest"
|
page_type="latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/queue')
|
@app.route('/queue')
|
||||||
def queue():
|
def queue():
|
||||||
if not session.get('authorized'):
|
if not session.get('authorized'):
|
||||||
return message("alert-danger", "You are not authorized to view this page.")
|
return message("alert-danger", "You are not authorized to view this page.")
|
||||||
|
|
||||||
quotes = Quote.query.filter_by(approved=False).order_by(Quote.id).all()
|
quotes = Quote.query.filter_by(approved=False).order_by(Quote.id).all()
|
||||||
|
|
||||||
if len(quotes)>0:
|
if len(quotes)>0:
|
||||||
# Replace line breaks with html breaks and escape special characters
|
# Replace line breaks with html breaks and escape special characters
|
||||||
for quote in quotes:
|
for quote in quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"queue.html",
|
"queue.html",
|
||||||
title="Queue",
|
title="Queue",
|
||||||
quotes=quotes
|
quotes=quotes
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes in the database.")
|
return message("alert-warning", "No quotes in the database.")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/moderate', methods=['POST'])
|
@app.route('/moderate', methods=['POST'])
|
||||||
def moderate():
|
def moderate():
|
||||||
if not session.get('authorized'):
|
if not session.get('authorized'):
|
||||||
return message("alert-danger", "You are not authorized to perform this action.")
|
return message("alert-danger", "You are not authorized to perform this action.")
|
||||||
|
|
||||||
if request.form['submit'] == "Approve":
|
if request.form['submit'] == "Approve":
|
||||||
quote = Quote.query.filter_by(id=request.form['quoteid']).first()
|
quote = Quote.query.filter_by(id=request.form['quoteid']).first()
|
||||||
quote.approved = True
|
quote.approved = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return message("alert-success", "Quote approved.")
|
return message("alert-success", "Quote approved.")
|
||||||
|
|
||||||
elif request.form['submit'] == "Delete":
|
elif request.form['submit'] == "Delete":
|
||||||
quote = Quote.query.filter_by(id=request.form['quoteid']).first()
|
quote = Quote.query.filter_by(id=request.form['quoteid']).first()
|
||||||
db.session.delete(quote)
|
db.session.delete(quote)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return message("alert-success", "Quote deleted.")
|
return message("alert-success", "Quote deleted.")
|
||||||
|
|
||||||
abort(501)
|
abort(501)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/quote/<int:id>')
|
@app.route('/quote/<int:id>')
|
||||||
def quote(id):
|
def quote(id):
|
||||||
quote = Quote.query.filter_by(id=id, approved=True).first()
|
quote = Quote.query.filter_by(id=id, approved=True).first()
|
||||||
|
|
||||||
if quote is None:
|
if quote is None:
|
||||||
return render_template(
|
return render_template(
|
||||||
"message.html",
|
"message.html",
|
||||||
alertclass="alert-warning",
|
alertclass="alert-warning",
|
||||||
message="No such quote."
|
message="No such quote."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Quote #{}".format(quote.id),
|
title="Quote #{}".format(quote.id),
|
||||||
quotes=[quote,],
|
quotes=[quote,],
|
||||||
numpages=1,
|
numpages=1,
|
||||||
curpage=0,
|
curpage=0,
|
||||||
page_type="quote"
|
page_type="quote"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/tag/<tagname>')
|
@app.route('/tag/<tagname>')
|
||||||
def tag(tagname):
|
def tag(tagname):
|
||||||
tag = Tag.query.filter_by(name=tagname).first()
|
tag = Tag.query.filter_by(name=tagname).first()
|
||||||
|
|
||||||
if len(list(tag.quotes))>0:
|
if len(list(tag.quotes))>0:
|
||||||
allquotes = len(list(tag.quotes))
|
allquotes = len(list(tag.quotes))
|
||||||
tag.quotes = tag.quotes[:10]
|
tag.quotes = tag.quotes[:10]
|
||||||
|
|
||||||
# Replace line breaks with html breaks and escape special characters
|
# Replace line breaks with html breaks and escape special characters
|
||||||
for quote in tag.quotes:
|
for quote in tag.quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Tag - {}".format(tagname),
|
title="Tag - {}".format(tagname),
|
||||||
quotes=tag.quotes,
|
quotes=tag.quotes,
|
||||||
numpages=1 + allquotes//10,
|
numpages=1 + allquotes//10,
|
||||||
curpage=0,
|
curpage=0,
|
||||||
page_type="tag/{}".format(tagname)
|
page_type="tag/{}".format(tagname)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return message("alert-warning", "No quotes with this tag.")
|
return message("alert-warning", "No quotes with this tag.")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/tag/<tagname>/<int:page>')
|
@app.route('/tag/<tagname>/<int:page>')
|
||||||
def tag_page(tagname, page):
|
def tag_page(tagname, page):
|
||||||
tag = Tag.query.filter_by(name=tagname).first()
|
tag = Tag.query.filter_by(name=tagname).first()
|
||||||
|
|
||||||
if len(list(tag.quotes))>0:
|
if len(list(tag.quotes))>0:
|
||||||
allquotes = len(list(tag.quotes))
|
allquotes = len(list(tag.quotes))
|
||||||
tag.quotes = tag.quotes[(page-1)*10:page*10]
|
tag.quotes = tag.quotes[(page-1)*10:page*10]
|
||||||
|
|
||||||
for quote in tag.quotes:
|
for quote in tag.quotes:
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"latest.html",
|
"latest.html",
|
||||||
title="Tag - {} - page {}".format(tagname, page),
|
title="Tag - {} - page {}".format(tagname, page),
|
||||||
quotes=tag.quotes,
|
quotes=tag.quotes,
|
||||||
numpages=1 + allquotes//10,
|
numpages=1 + allquotes//10,
|
||||||
curpage=0,
|
curpage=0,
|
||||||
page_type="tag/{}".format(tagname)
|
page_type="tag/{}".format(tagname)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/tags')
|
@app.route('/tags')
|
||||||
def tags():
|
def tags():
|
||||||
tags = Tag.query.order_by(Tag.name).distinct().all()
|
tags = Tag.query.order_by(Tag.name).distinct().all()
|
||||||
tags = list(set([x.name for x in tags]))
|
tags = list(set([x.name for x in tags]))
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"tags.html",
|
"tags.html",
|
||||||
title="Tags",
|
title="Tags",
|
||||||
tags=tags
|
tags=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':
|
||||||
|
return render_template(
|
||||||
allquotes = len(quotes)
|
"message.html",
|
||||||
quotes = quotes[:10]
|
alertclass="alert-warning",
|
||||||
|
message="Not implemented yet. "
|
||||||
if len(quotes)>0:
|
)
|
||||||
# Replace line breaks with html breaks and escape special characters
|
else:
|
||||||
for quote in quotes:
|
return 'Invalid request.'
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
|
||||||
|
|
||||||
return render_template(
|
@app.route('/add', methods=['GET', 'POST'])
|
||||||
"search.html",
|
def add_new():
|
||||||
title="Search for: {}".format(query),
|
if request.method == 'POST':
|
||||||
quotes=quotes,
|
if request.form['submit'] == "Submit":
|
||||||
numpages=1 + allquotes//10,
|
quote_body = request.form["newquote"]
|
||||||
curpage=0,
|
quote_tags = request.form["tags"].split(',')
|
||||||
page_type="search",
|
|
||||||
search_query=query
|
quote = Quote(quote_body, request.remote_addr, timestamp())
|
||||||
)
|
quote_tags = [Tag(tag) for tag in quote_tags]
|
||||||
else:
|
|
||||||
return message("alert-warning", "No quotes in the database.")
|
for tag in quote_tags:
|
||||||
|
dbtag = Tag.query.filter_by(name=tag.name).first()
|
||||||
|
if dbtag is not None:
|
||||||
@app.route('/search/<query>/<int:page>')
|
quote.tags.append(dbtag)
|
||||||
def search_page(query, page):
|
else:
|
||||||
allquotes = len(Quote.query.filter_by(approved=True).\
|
quote.tags.append(tag)
|
||||||
filter(Quote.content.ilike('%{}%'.format(query))).\
|
#quote.tags.extend(quote_tags)
|
||||||
order_by(Quote.id.desc()).all())
|
|
||||||
quotes = Quote.query.filter_by(approved=True).\
|
db.session.add(quote)
|
||||||
filter(Quote.content.ilike('%{}%'.format(query))).\
|
db.session.commit()
|
||||||
order_by(Quote.id.desc()).all()[(page-1)*10:page*10]
|
|
||||||
|
return render_template(
|
||||||
for quote in quotes:
|
"message.html",
|
||||||
quote.content = str(Markup.escape(quote.content)).replace('\n', '</br>')
|
alertclass="alert-success",
|
||||||
|
message="Quote added succesfully. It will need to be reviewed by the administrators before it shows up."
|
||||||
return render_template(
|
)
|
||||||
"search.html",
|
|
||||||
title="Search for: {} - page {}".format(query, page),
|
elif request.form['submit'] == "Preview":
|
||||||
quotes=quotes,
|
return str(request.form)
|
||||||
numpages=1 + allquotes//10,
|
else:
|
||||||
curpage=page-1,
|
abort(501)
|
||||||
page_type="search",
|
|
||||||
search_query=query
|
elif request.method == 'GET':
|
||||||
)
|
return render_template(
|
||||||
|
"add.html",
|
||||||
|
title="Add new"
|
||||||
@app.route('/add', methods=['GET', 'POST'])
|
)
|
||||||
def add_new():
|
|
||||||
if request.method == 'POST':
|
|
||||||
if request.form['submit'] == "Submit":
|
|
||||||
quote_body = request.form["newquote"]
|
|
||||||
quote_tags = request.form["tags"].split(',')
|
|
||||||
|
|
||||||
quote = Quote(quote_body, request.remote_addr, timestamp())
|
|
||||||
quote_tags = [Tag(tag) for tag in quote_tags]
|
|
||||||
|
|
||||||
for tag in quote_tags:
|
|
||||||
dbtag = Tag.query.filter_by(name=tag.name).first()
|
|
||||||
if dbtag is not None:
|
|
||||||
quote.tags.append(dbtag)
|
|
||||||
else:
|
|
||||||
quote.tags.append(tag)
|
|
||||||
#quote.tags.extend(quote_tags)
|
|
||||||
|
|
||||||
db.session.add(quote)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
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":
|
|
||||||
preview = Quote(request.form['newquote'], request.remote_addr, timestamp())
|
|
||||||
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:
|
|
||||||
abort(501)
|
|
||||||
|
|
||||||
elif request.method == 'GET':
|
|
||||||
return render_template(
|
|
||||||
"add.html",
|
|
||||||
title="Add new"
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue