-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
57 lines (48 loc) · 1.82 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#imports, settings, functions, blueprints
#imports
from flask import Flask, url_for, render_template, flash, redirect
from flask_modus import Modus
from flask_login import LoginManager
from flask_bcrypt import Bcrypt
from flask_sqlalchemy import SQLAlchemy
import os
#settings
app = Flask(__name__)
modus = Modus(app)
bcrypt = Bcrypt(app)
if os.environ.get('ENV') == 'production':
app.config.from_object('config.ProductionConfig')
else:
app.config.from_object('config.Config')
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'users.login'
login_manager.login_message = 'Please log in!'
#functions
@app.context_processor #http://flask.pocoo.org/snippets/40/
def override_url_for():
return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path,
endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)
#blueprints
from project.users.views import users_blueprint
from project.prompts.views import prompts_blueprint
from project.responses.views import responses_blueprint
from project.matches.views import matches_blueprint
app.register_blueprint(users_blueprint, url_prefix="/users")
app.register_blueprint(prompts_blueprint, url_prefix="/users/<int:user_id>/prompts")
app.register_blueprint(responses_blueprint, url_prefix="/users/<int:user_id>/prompts/<int:prompt_id>/responses")
app.register_blueprint(matches_blueprint, url_prefix="/users/<int:user_id>/matches")
@app.route('/')
def root():
return redirect(url_for('users.index'))
@app.errorhandler(404)
def exception_handler(e):
return render_template('404.html'), 404