-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
65 lines (54 loc) · 1.87 KB
/
index.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
import os
import sys
from flask import Flask, render_template, redirect, url_for
from tools import user_is_authorized, user_info, get_categories
# our routes storred as blueprints
# for better code distribution and reusability
from auth_blueprint import auth
from category_blueprint import category
from item_blueprint import item
from api_blueprint import api
app = Flask(__name__)
app.secret_key = 'This is placeholder for secret key and must be replaced'
app.register_blueprint(auth)
app.register_blueprint(category)
app.register_blueprint(item)
app.register_blueprint(api)
@app.route('/', methods=['GET'])
def index_route():
"""
Home sweet home, this is page where our journey begins
"""
return render_template('index.html', page={
'title': 'Homepage',
'has_sidebar': True
}, user=user_info(), content={
'categories': get_categories()
})
@app.route('/profile', methods=['GET'])
def profile_route():
"""
Originaly I planned to make it big and coolm with API key to update
and delete stuff, with nice API reference and so on.
Then I understood that this is overkill,
so this page is very simple and just shows user's picture.
"""
user = user_info()
if not user_is_authorized():
return redirect(url_for('auth.login_route'))
return render_template('profile.html', page={
'title': user['name'] + ' profile'
}, user=user, content={
'categories': get_categories()
})
if __name__ == '__main__':
args_number = len(sys.argv)
if args_number > 0 and '--production' not in sys.argv:
print('WARNING: running in debug mode\n\
add `--production` flag to run in production mode')
# for OAuth on http localhost
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
app.debug = True
else:
app.debug = False
app.run(host='0.0.0.0', port=5000)