-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
83 lines (63 loc) · 2.3 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from flask import Flask, render_template, request, redirect, url_for, flash, \
Response, session, Blueprint, send_file, make_response, jsonify
from flask_bootstrap import Bootstrap
from filters import datetimeformat, file_type
from flask_login import login_required, current_user
# from . import db
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from resources import get_bucket, get_buckets_list
app = Flask(__name__)
Bootstrap(app)
app.secret_key = 'secret-key'
app.jinja_env.filters['datetimeformat'] = datetimeformat
app.jinja_env.filters['file_type'] = file_type
db = SQLAlchemy()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/profile')
@login_required
def profile():
return render_template("profile.html", name=current_user.name)
@app.route('/bucket', methods=['GET', 'POST'])
@login_required
def bucket():
if request.method == 'POST':
bucket = request.form['bucket']
session['bucket'] = bucket
return redirect(url_for('files'))
else:
buckets = get_buckets_list()
return render_template("bucket.html", buckets=buckets)
@app.route('/files')
@login_required
def files():
my_bucket = get_bucket()
summaries = my_bucket.objects.all()
return render_template('files.html', my_bucket=my_bucket, files=summaries)
def create_app():
app.config['SECRET_KEY'] = 'secret-key-goes-here'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
db.init_app(app)
from auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)
app_blueprint = Blueprint('app', __name__)
app.register_blueprint(app_blueprint)
return app
def run_app():
app.config['SECRET_KEY'] = 'secret-key-goes-here'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
db.init_app(app)
from auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
from models import User
return User.query.get(int(user_id))
app.run(debug=True)
if __name__ == "__main__":
run_app()