2018-06-26 21:48:25 +00:00
|
|
|
from datetime import datetime
|
2018-10-25 18:47:31 +00:00
|
|
|
from flask import session, g, request
|
2018-06-26 21:48:25 +00:00
|
|
|
import settings
|
2018-09-05 22:27:26 +00:00
|
|
|
from funding.bin.utils import Summary
|
2020-06-09 02:32:51 +00:00
|
|
|
from funding.factory import app, db
|
2018-09-05 22:27:26 +00:00
|
|
|
from funding.orm.orm import Proposal, User, Comment
|
2018-06-26 21:48:25 +00:00
|
|
|
|
2018-10-25 18:47:31 +00:00
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
@app.context_processor
|
2018-07-04 14:04:19 +00:00
|
|
|
def templating():
|
2020-06-09 02:32:51 +00:00
|
|
|
from flask_login import current_user
|
|
|
|
recent_comments = db.session.query(Comment).filter(Comment.automated == False).order_by(Comment.date_added.desc()).limit(8).all()
|
2018-07-12 00:39:49 +00:00
|
|
|
summary_data = Summary.fetch_stats()
|
2020-06-09 02:32:51 +00:00
|
|
|
newest_users = db.session.query(User).filter(User.admin == False).order_by(User.registered_on.desc()).limit(5).all()
|
2018-07-04 14:04:19 +00:00
|
|
|
return dict(logged_in=current_user.is_authenticated,
|
|
|
|
current_user=current_user,
|
|
|
|
funding_categories=settings.FUNDING_CATEGORIES,
|
2018-07-04 17:50:36 +00:00
|
|
|
funding_statuses=settings.FUNDING_STATUSES,
|
2018-07-12 00:39:49 +00:00
|
|
|
summary_data=summary_data,
|
2018-09-05 22:27:26 +00:00
|
|
|
recent_comments=recent_comments,
|
|
|
|
newest_users=newest_users)
|
2018-06-26 21:48:25 +00:00
|
|
|
|
2018-10-25 18:47:31 +00:00
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
@app.before_request
|
|
|
|
def before_request():
|
2018-07-12 00:39:49 +00:00
|
|
|
pass
|
2018-06-26 21:48:25 +00:00
|
|
|
|
2018-10-25 18:47:31 +00:00
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
@app.after_request
|
|
|
|
def after_request(res):
|
|
|
|
res.headers.add('Accept-Ranges', 'bytes')
|
2018-10-25 18:47:31 +00:00
|
|
|
|
|
|
|
if request.full_path.startswith('/api/'):
|
|
|
|
res.headers.add('Access-Control-Allow-Origin', '*')
|
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
if settings.DEBUG:
|
|
|
|
res.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
|
|
|
res.headers['Pragma'] = 'no-cache'
|
|
|
|
res.headers['Expires'] = '0'
|
|
|
|
res.headers['Cache-Control'] = 'public, max-age=0'
|
|
|
|
return res
|
|
|
|
|
2018-10-25 18:47:31 +00:00
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
@app.teardown_appcontext
|
|
|
|
def shutdown_session(**kwargs):
|
2020-06-09 02:32:51 +00:00
|
|
|
db.session.remove()
|
2018-06-26 21:48:25 +00:00
|
|
|
|
2018-10-25 18:47:31 +00:00
|
|
|
|
2018-06-26 21:48:25 +00:00
|
|
|
@app.errorhandler(404)
|
|
|
|
def error(err):
|
2018-10-25 18:47:31 +00:00
|
|
|
return 'Error', 404
|