-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (39 loc) · 1.69 KB
/
main.py
File metadata and controls
52 lines (39 loc) · 1.69 KB
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
import json
import flask
from dailys_web.blueprints.forms import FormsBlueprint
from dailys_web.blueprints.stats import StatsBlueprint
from dailys_web.blueprints.views.blueprint import ViewsBlueprint
from dailys_web.data_source.postgres import PostgresDataSource
from dailys_web.decorators import view_auth_required, get_auth_key
from dailys_web.path_converters import DateConverter, EndDateConverter, SpecifiedDayConverter, StartDateConverter
# Load converters
app = flask.Flask(__name__)
app.url_map.converters['date'] = DateConverter
app.url_map.converters['start_date'] = StartDateConverter
app.url_map.converters['end_date'] = EndDateConverter
app.url_map.converters['view_date'] = SpecifiedDayConverter
with open("config.json", "r") as f:
CONFIG = json.load(f)
@app.route("/")
def hello_world():
return "Hello, World! This is Spangle's dailys recording system."
@app.route("/login")
def login_form():
return flask.render_template("login_form.html")
@view_auth_required
@app.route("/login", methods=["POST"])
def login_submit():
auth_key = get_auth_key("view_auth_key")
resp = flask.make_response("Logged in")
resp.set_cookie('view_auth_key', auth_key, max_age=86400*100)
return resp
data_source = PostgresDataSource(CONFIG["database"])
stats_blueprint = StatsBlueprint(data_source)
stats_blueprint.register()
app.register_blueprint(stats_blueprint.blueprint, url_prefix="/stats")
views_blueprint = ViewsBlueprint(data_source, CONFIG)
views_blueprint.register()
app.register_blueprint(views_blueprint.blueprint, url_prefix="/views")
forms_blueprint = FormsBlueprint(data_source, CONFIG)
forms_blueprint.register()
app.register_blueprint(forms_blueprint.blueprint, url_prefix="/forms")